Class: Embryo::RubyTemplate::Action::Destroy
Instance Method Summary
collapse
#initialize
#text
Instance Method Details
#controller_method_code ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/rails-embryo/ruby_template/action/destroy.rb', line 5
def controller_method_code
method_code :destroy,
"if @#{model.singular}.destroy",
indent("redirect_to #{@model.plural_symbol}_path, notice: \"#{model.singular.capitalize} deleted.\""),
"else",
indent("redirect_to #{@model.plural_symbol}_path, alert: \"Couldn't delete #{model.singular}.\""),
"end"
end
|
#controller_spec_code ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/rails-embryo/ruby_template/action/destroy.rb', line 14
def controller_spec_code
spec_group_code "#destroy",
spec_context_code("when successful",
spec_before_code(
"@#{model.singular} = create :#{model.symbol}",
"delete :destroy, id: @#{model.singular}.id"
),
spec_code("destroys the #{model.singular}",
"expect(#{model.class_name}.all).not_to include @#{model.singular}"),
spec_code("redirects to the index",
"expect(response).to redirect_to #{model.plural_symbol}_path"))
end
|