Sha256: e3001dddd54499083b602277f0d831197cfc826a26b63a09fb539e409c259dc4

Contents?: true

Size: 1.49 KB

Versions: 8

Compression:

Stored size: 1.49 KB

Contents

<% if File.exist?(File.join %w[spec rails_helper.rb]) -%>
require 'rails_helper'
<% else -%>
require 'spec_helper'
<% end -%>

<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
describe "<%= ns_table_name %>/new", type: :view do
  before(:each) do
<% if Rails.application.config.generators.options[:rails][:cancan] -%>
    allow(controller).to receive(:can?).and_return(true)
<% end -%>
<% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
    @<%= ns_file_name %> = assign(:<%= ns_file_name %>, build(:<%= ns_file_name %>))
  end
<% else -%>
    assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
      <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
<%= !output_attributes.empty? ? "    ))\n  end" : "  end" %>
<% end -%>

  it "renders new <%= ns_file_name %> form" do
    render

    assert_select "form[action='#{<%= index_helper %>_path}'][method='post']" do
<% for attribute in output_attributes -%>
<% name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
<% input_type = attribute.reference? ? 'select' : attribute.input_type -%>
      assert_select '<%= input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]', '<%= ns_file_name %>[<%= name %>]'
<% end -%>
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rspec_rails_scaffold_templates-1.2.5 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.2.4 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.2.3 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.2.2 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.2.1 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.2.0 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.1.1 lib/templates/rspec/scaffold/new_spec.rb
rspec_rails_scaffold_templates-1.1.0 lib/templates/rspec/scaffold/new_spec.rb