Sha256: 88e7c16d15e6dba2644e2a2fce87074c0f4e49ce718804475bc93218f59555b7

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 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 %>/show", :type => :view do
  before(:each) do
    allow(controller).to receive(:can?).and_return(true)
<% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
    @<%= ns_file_name %> = assign(:<%= ns_file_name %>, create(:<%= ns_file_name %>))
<% else -%>
    @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' 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 -%>
<% if !output_attributes.empty? -%>
    ))
<% end -%>
<% end -%>
  end

  it "renders attributes in <p>" do
    render
<% for attribute in output_attributes -%>
<% if Rails.application.config.generators.options[:rails][:fixture_replacement] == :factory_girl -%>
<% if attribute.reference? -%>
    expect(rendered).to match(Regexp.new @<%= ns_file_name %>.<%= attribute.name %>.name)
<% else -%>
    expect(rendered).to match(Regexp.new @<%= ns_file_name %>.<%= attribute.name %>.to_s)
<% end -%>
<% else -%>
    expect(rendered).to match(/<%= raw_value_for(attribute) %>/)
<% end -%>
<% end -%>
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec_rails_scaffold_templates-1.0.4 lib/templates/rspec/scaffold/show_spec.rb
rspec_rails_scaffold_templates-1.0.3 lib/templates/rspec/scaffold/show_spec.rb
rspec_rails_scaffold_templates-1.0.2 lib/templates/rspec/scaffold/show_spec.rb
rspec_rails_scaffold_templates-1.0.1 lib/templates/rspec/scaffold/show_spec.rb
rspec_rails_scaffold_templates-1.0.0 lib/templates/rspec/scaffold/show_spec.rb