learn-co-curriculum / rails-generators-readme Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
In spec/features/post_spec.rb, the post instance variable needs a category assigned before testing, since this is required for the view tests
In spec/models/category_spec.rb, the test needs to check respond_to on an instance of the Category class (maybe)
RSpec.describe Category, type: :model do
describe "relations" do
it 'has many posts' do
@category = Category.new
expect(@category).to respond_to(:posts)
end
end
end
Line 7 has a lower case 'c'.
expect(category.new).to respond_to(:posts)
should be:
expect(Category.new).to respond_to(:posts)
Referring to this line of the read me:
Author.create!(name: "Stephen King", genre: "Horror", bio: "Bio details go here")
While following along with the code-along, After invoking the following command:
rails g model Author name:string genre:string bio:text --no-test-framework
The following resulted:
invoke active_record
create db/migrate/20190618010724_create_authors.rb
create app/models/application_record.rb
create app/models/author.rb
It added an application_record.rb file.
Additionally, class Author inherits from Application Record as such:
class Author < ApplicationRecord
end
I believe the material needs to be updated to reflect the changes in Rails 5. I found some information here: https://blog.bigbinary.com/2015/12/28/application-record-in-rails-5.html
and here: https://stackoverflow.com/questions/37359527/why-rails-5-uses-applicationrecord-instead-of-activerecordbase
I think the material in this lesson should be updated accordingly.
Hoping this will help learn creators to help future learn students.
NVM, I was reading the wrong part.
I added a before hook so there would be a category when it gets :show; otherwise, it won't work.
Also, previous poster is correct about the logic in app/models/post.rb. The rspec for that needs to check for title caps, since that's how the validation works. Updated mine so it passes.
I have forked this lab, run the tests and submitted. But the lab doesn't reflect it. Could you please help? Here is my git repository: https://github.com/dmcgrann/rails-generators-readme-v-000
Thanks.
In the v-000 deployment of this lab there is some logic in the app/modules/post.rb file that Capitalizes The First Letter of the title. The spec is looking for the title to be "My edit". It looks like student keep editing the spec to pass the test. It seems either that logic should be removed, or the spec should be updated.
It would be great to explain us how to use ' --no-test-framework' flag, so that we don't have to confused for the automatically generated pending tests!
Cannot call .new on an instance variable. Currently:
expect(category.new).to respond_to(:posts)
Should be:
expect(Category.new).to respond_to(:posts)
"We can simply add in the change_column
method like this: change_column :posts, :post_status, :string
and after running rake db:migrate
our schema will be updated."
Changing the post_status to string makes the test fail.
I kept getting an error after I was done with all my generators and I was able to fix it by changing the update
method and adding a new method post_params(*args)
.
def update
# @post = Post.find(params[:id])
# @post.update(params.require(:post))
# redirect_to post_path(@post)
@post = Post.find(params[:id])
@post.update(post_params(:title))
redirect_to post_path(@post)
end
private
def post_params(*args)
params.require(:post).permit(*args)
end
This need to be fixed by someone so it won't keep showing errors that are not explained in the readme.
A test is improperly written. It should be modified this way:
describe "GET #show" do
before do
@category = Category.create(name: "hello category")
end
it "returns http success" do
get :show, {:id => @category.id}
expect(response).to have_http_status(:success)
end
end
Hi. The current spec test in category_sec.rb does not work . The class Category will not respond to :posts. It is an INSTANCE of class Category that will respond to :posts. Here is the revised spec test that works.
RSpec.describe Category, type: :model do
describe 'relations' do
it 'has many posts' do
@category = Category.create(name: "NewCategory")
expect(@category).to respond_to(:posts)
end
end
end
When the README renders in canvas it leaves off about half the information.
Readme is different than the fork by quite a margin. Initial tests fail and are confusing in context. Is this intended?
Line 4: Add "bio" since example seems to show it along columns for name and genre
Model Generators
This is a generator type that gets used regularly. It does a great job of creating the core code needed to create a model and associated database table without adding a lot of bloat to the application. Let's add a new model to the app called Author with columns name and genre, we can use the model generator with the following CLI command:
rails g model Author name:string genre:string bio:text --no-test-framework
Post.count
clickbait = Category.find_by(name: "Clickbait")
clickbait.posts.count
Line 3 in db/seeds.rb:
clickbait = Category.create!(name: "Motivation")
Line 3: in rails console commands, should submit "Motivation" as value, not "Clickbait"
clickbait = Category.find_by(name: "Clickbait")
should be
clickbait = Category.find_by(name: "Motivation") #matching the seed
clickbait.posts.count will then return 3. otherwise it crashes.
I've submitted an edit to this lesson but it seems more like an issue to me now that I think about it. The lab walks you through changing a column and during that change you set post_status from a boolean to a string. The issue here is that if we do change the column to string type as the lab says, rspec fails because it is looking for a boolean value.
There may need to be a different change_column done or have the rspec check for a string value. Either one of those should fix it up.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.