lib/generators/leolay/templates/lib/templates/rspec/scaffold/index_spec.rb in leonardo-1.5.0 vs lib/generators/leolay/templates/lib/templates/rspec/scaffold/index_spec.rb in leonardo-1.6.0

- old
+ new

@@ -15,20 +15,31 @@ "#{name} => (r.#{attribute.name}.try(:name) || r.#{attribute.name}.try(:id))" when :boolean nil else "#{name} => r.#{attribute.name}" - end << - ":count => 1" + end ).compact.join(', ') end %> <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%> describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>" do before(:each) do - @records = assign(:<%= table_name %>, FactoryGirl.create_list(:<%= ns_file_name %>, 2) ) - assign(:<%= ns_file_name %>, Factory(:<%= ns_file_name %>) ) + <%- parents = []; str_parents_create = str_parents_where = "" -%> + <%- base_parent_resources.each do |parent| -%> + @<%= parent %> = assign(:<%= parent %>, Factory(:<%= parent %>) ) + <%- parents << ":#{parent}_id => @#{parent}.id" -%> + <%- end -%> + <%- str_parents_create = ", #{parents.join(', ')}" if parents.any? -%> + <%- str_parents_where = ".where(#{parents.join(', ')})" if parents.any? -%> + <%- if pagination? -%> + FactoryGirl.create_list(:<%= ns_file_name %>, 2<%= str_parents_create %>) + @records = assign(:<%= table_name %>, <%= class_name %><%= str_parents_where %>.order(:id).page(1) ) + <%- else -%> + @records = assign(:<%= table_name %>, FactoryGirl.create_list(:<%= ns_file_name %>, 2<%= str_parents_create %>) ) + <%- end -%> + assign(:<%= ns_file_name %>, Factory.build(:<%= ns_file_name %>) ) end it "renders a list of <%= ns_table_name %>" do render @records.each do |r| \ No newline at end of file