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
Conversation
end | ||
it "assigns all charts as @charts" do | ||
(1..5).each { |num| Chart.new(id: num, title: 'fabrication') } | ||
charts = Chart.all |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fabricate.times(4, :chart)
There was a problem hiding this comment.
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)
There was a problem hiding this 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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fabricate.times(4, :chart)
work in progress...