Class: Embryo::RubyTemplate::Action::Create
Instance Method Summary
collapse
#initialize
#text
Instance Method Details
#controller_method_code ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/rails-embryo/ruby_template/action/create.rb', line 5
def controller_method_code
method_code :create,
"@#{model.singular} = #{model.class_name}.new #{model.singular}_params",
"if @#{model.singular}.save",
indent("redirect_to #{@model.plural_symbol}_path, notice: \"#{model.singular.capitalize} created.\""),
"else",
indent("render :new"),
"end"
end
|
#controller_spec_code ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/rails-embryo/ruby_template/action/create.rb', line 15
def controller_spec_code
spec_group_code "#create",
spec_context_code("with valid attributes",
spec_before_code("post :create, #{model.singular}: attributes_for(:#{model.symbol})"),
spec_code("creates a new #{model.singular}",
"expect(assigns :#{model.singular}).to be_a #{model.class_name}"),
spec_code("redirects to the index on success",
"expect(response).to redirect_to #{model.plural_symbol}_path"))
end
|