Sha256: d09f65a6d87d2950b5666d1b948fb295073b5f2ed1b4ba9aeb360742f178a713
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
<% if File.exist?(File.join %w[spec rails_helper.rb]) -%> require 'rails_helper' <% else -%> require 'spec_helper' <% end -%> describe "<%= ns_table_name %>/index.json.jbuilder", 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 %> = create(:<%= ns_file_name %>) <% else -%> @<%= ns_file_name %> = <%= class_name %>.create(<%= attributes.empty? ? ')' : '' %> <% attributes.each_with_index do |attribute, attribute_index| -%> :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == attributes.length - 1 ? '' : ','%> <% end -%> ) <% end -%> assign :<%= table_name %>, [@<%= ns_file_name %>, @<%= ns_file_name %>] end attributes = %w[ id <% for attribute in attributes -%> <%= attribute.name %> <% end -%> url ] it "renders a list of <%= table_name %> as json with following attributes: #{attributes.join(', ')}" do render hash = MultiJson.load rendered expect(hash.first).to eq(hash = hash.last) expect(hash.keys.sort).to eq attributes.sort expected = @<%= ns_file_name %>.attributes.slice *attributes expected = MultiJson.load MultiJson.dump expected expected['url'] = <%= ns_file_name %>_url(@<%= ns_file_name %>, format: 'json') expect(hash).to eq expected <% for attribute in attributes + ['id'] -%> # expect(hash['<%= attribute.name %>']).to eq @<%= ns_file_name %>.<%= attribute.name %>.to_s <% end -%> # expect(hash['url']).to eq <%= ns_file_name %>_url(@<%= ns_file_name %>, format: 'json') end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jbuilder_rspec_generator-1.0.6 | lib/generators/rspec/templates/index_spec.rb |