Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index #3

Merged
merged 9 commits into from Jan 16, 2017
Merged

Add index #3

merged 9 commits into from Jan 16, 2017

Conversation

Netznarkose
Copy link
Collaborator

work in progress...

end
it "assigns all charts as @charts" do
(1..5).each { |num| Chart.new(id: num, title: 'fabrication') }
charts = Chart.all
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been doing some searching but I could not find out how to create a collection of a Model ( Chart::ActiveRecord_Relation) in Fabrication ruby @charts = plenty of Fabrication(:chart) do you have an idea?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fabricate.times(4, :chart)

Copy link
Owner

@eikes eikes Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fabricate.times(4, :chart).class
=> Array
and not 
=> Chart::ActiveRecord_Relation

You could do it like you did above:

Fabricate.times(4, :chart)
get :index
expect(assigns(:charts)).to eq(Chart.all)

Copy link
Owner

@eikes eikes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

<h1>Listing Charts</h1>

<table>
<thead>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a table head if you don't put anything into it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One Other current Issue
since I've implemented this:

class Chart < ActiveRecord::Base
 validates :data, presence: true
end

this spec does not pass anymore
charts_controller_spec

      it 'creates a new Chart' do
        expect {
          post :create, chart: valid_attributes
        }.to change(Chart, :count).by(1)
      end

and I have no Idea.... because manually I can create entries

Failures:

  1) ChartsController POST #create with valid params creates a new Chart
     Failure/Error:
       expect {
         post :create, chart: valid_attributes
       }.to change(Chart, :count).by(1)

       expected #count to have changed by 1, but was changed by 0
     # ./spec/controllers/charts_controller_spec.rb:70:in `block (4 levels) in <top (required)>'

Finished in 0.63365 seconds (files took 8.88 seconds to load)
1 example, 1 failure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or could Database Cleaner be the reason?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your valid_attributes now need to include the data_attributes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I just found out myself, thanks

end
it "assigns all charts as @charts" do
(1..5).each { |num| Chart.new(id: num, title: 'fabrication') }
charts = Chart.all
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fabricate.times(4, :chart)

@eikes eikes merged commit 39c7ed3 into master Jan 16, 2017
@Netznarkose Netznarkose deleted the add_index branch January 20, 2017 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants