learn-co-curriculum / activerecord-crud Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
There are currently no specs/tests to run. There is also no ReadMe as it looks like the readme was removed a few days ago and not replaced. As of now, when the lab page on Learn.co loads, it is completely empty, and there are no tests to pass or even work towards.
in Movie_spec.rb: The current test passes by default (without using the method being tested.
it 'can be updated using #update' do
Movie.create(title: "Wat?")
movie = Movie.find_by(title: "Wat?")
movie.update(title: "Wat, huh?")
expect(Movie.find_by(title: "Wat, huh?")).to_not be_nil
end
Can be changed to:
it 'can be updated using #update' do
can_update_using_update_method
expect(Movie.find_by(title: "Wat, huh?")).to_not be_nil
end
@StevenNunez @SophieDeBenedetto @antoinfive
this should help https://guides.rubyonrails.org/active_record_basics.html - Chris Henry
Please be more specific as to what you want us to do this. Maybe by adding a description. Thank you.
def can_be_created_in_a_block
Movie.create do |m|
__
end
end
In this lab, the spec asks for us to create a new instance of movie with a block with the #create method.
We figured out that unless you hardcore what the test is passing:
it 'can be created in a block' do
movie = can_be_created_in_a_block
expect(Movie.last).to eq(movie)
expect(Movie.last.title).to eq("Home Alone")
expect(Movie.last.release_date).to eq(1990)
end
--
There is no way to pass the spec. It is specifically asks you to solve this problem with one line of code, but based on the fact there are no arguments it is impossible.
--
We have confirmation from JJ that this is true.
:) <3
My schema.rb that was auto-generated after migration defined the data types incorrectly for t.string "release_date" and t.string "in_theaters". The data type for "release_date" should be date. The data type for "in_theaters" should be boolean.
After trying for couple hours, I was unable to find a fix.
Thank you
i did pass them - am i doing something wrong?
I got a notification that the starter code in this lab was fixed so as not to throw a syntax error anymore. However, a student just popped up on AAQ with the same issue. The underscores between the {} are causing it.
The spec file here is pretty magical and important. The point of the lab is to recognize all the sort of methods that AR provides on a convention-oriented class (that wraps a DB table). You get accessors for each column. CRUD methods. Finders. Etc. This lab should either tell the student or force the student somehow to recognize the common AR interface.
The lab is not marked as done in the full stack tree on the left side (curriculum) despite it was solved.
Boodstrap issue.pdf
There are blanks for students to fill in denoted by "__" in several spots. The ones that appear in between the curly braces are causing a syntax error.
Students can create table schema correctly for models but tests still fail. Tests check for in_theatRES but the rest of the lab uses in_theatERS.
Method names in movie_controller.rb file (below) and the spec file are ambiguous.
They ask to return the first item in the database where as it is expecting the title of the first item in the database.
def can_get_the_first_item_in_the_database
end
def can_get_the_last_item_in_the_database
end
Method names
when running bundle
:
An error occurred while installing eventmachine (1.2.7), and Bundler cannot continue. Make sure that
gem install eventmachine -v '1.2.7' --source 'https://rubygems.org/'`
succeeds before bundling.`
and when attempting to run learn
:
`Bundler could not find compatible versions for gem "eventmachine":
In Gemfile:
thin was resolved to 1.7.2, which depends on
eventmachine (~> 1.0, >= 1.0.4)
Could not find gem 'eventmachine (~> 1.0, >= 1.0.4)', which is required by gem 'thin', in any of the sources.`
brew install openssl
returned that openssl was already installed, and running brew link openssl --force
didn't resolve the problem.
All the content of this lab isn't discussed until Intro to Rake, which is the lesson after this one.
One student got this error when trying to run bundle install (needed to run rspec test):
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
sinatra-activerecord was resolved to 2.0.9, which depends on
activerecord was resolved to 4.2.6, which depends on
activemodel was resolved to 4.2.6, which depends on
activesupport was resolved to 4.2.6, which depends on
json
Running 'gem install json -v '1.8.3' did not work and threw error messages. Solution below:
$ bundle update json
$ bundle install
After this rspec could run.
after typed 'bundle install' in command line:
An error occurred while installing eventmachine (1.0.7), and Bundler cannot
continue.
Make sure that gem install eventmachine -v '1.0.7'
succeeds before bundling.
so i changed
eventmachine (1.0.7) to eventmachine (1.2.0.1) in Gemfile.lock
and then typed 'gem install eventmachine' ,the bundle worked...
When I was doing the spec for 'can_get_size_of_the_database' I was thinking of how to approach it, My first try was to do Movie.last.id which would give the ID of the last movie added which would be the size of the database under normal circumstances.
I then realized that that shouldn't be the correct answer because it won't account for a case where a record was deleted, nevertheless it still passed the test.
You might want to change the test to account for that? Maybe by creating a movie with an ID greater than 5?
Would be lovely, and much easier to read!
Ta very much!
I had an error when I run "learn" in the terminal and I got error. It was fixed when i changed Gemfile to be. I changed 'sqlite3', '>1.3.6' to be 'sqlite3', '>1.4'.
The snippet below is from movies_controller.rb
. It fails the test, but only because the given method name is incorrect. Upon changing the word "different", to "multiple". The tests pass. If that was to intentionally challenge us, then right on! It made me pay attention to detail and examine the error message closely.
def can_find_by_different_attributes
# title == "Title"
# release_date == 2000,
# director == "Me"
Movie.find_by(title: "Title", release_date: 2000, director: "Me")
end
even if the students type something that doesn't makes sense into the block (#can_be_created_in_a_block) the test passes.
This lab doesn't work, It gave error when i run learn before typing any line of code. I asked a question and tried with Coach but he has same error.
The error is
D, [2019-08-17T11:47:25.299971 #11258] DEBUG -- : (1.3ms) SELECT sqlite_version(*)
An error occurred while loading spec_helper.
Failure/Error: raise 'Migrations are pending. Run `rake db:migrate SINATRA_ENV=test` to resolve the issue.'
RuntimeError:
Migrations are pending. Run `rake db:migrate SINATRA_ENV=test` to resolve theissue.
# ./spec/spec_helper.rb:8:in `<top (required)>'
Finished in 0.00171 seconds (files took 1.46 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
Finished in 0.00171 seconds (files took 1.46 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
When I tried rake db:migrate SINATRA_ENV=test
it gave me
rake db:migrate SINATRA_ENV=test
rake aborted!
LoadError: cannot load such file -- sinatra/activerecord/rake/activerecord_6
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/usr/local/rvm/gems/ruby-2.6.1/gems/sinatra-activerecord-2.0.13/lib/sinatra/activerecord/rake.rb:2:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/home/proactive-karma-6410/activerecord-crud-online-web-ft-071519/Rakefile:4:in`<top (required)>'
/usr/local/rvm/gems/ruby-2.6.1/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace)
It appears this lab may have been intended to be placed later in the ActiveRecord section, as it requires that the student write migrations, despite there being no migration curriculum material inside of or before this lab (there are three lessons involving migrations that follow it).
movies_controller.rb:
#can_find_by_different_attributes
movie_spec.rb
#can_find_by_multiple_attributes
These should be the same.
I had some issues installing the above Gem required in the Gemfile on El Capitan.
Found this to help and solved my issues. May be worth putting in the notes...
I think that line 109 in movie_spec.rb should have an argument name of can_find_by_different_attributes so that there isn't an undefined method error.
The json (1.8.3)
in the Gemfile.lock
causes issues. Deleting Gemfile.lock
then running bundle
resolves the install issue.
README instructions say that "In each method the __ corresponds to a line of code you will need to write to make the spec pass."
Add the __ to show that more code should be added.
Line 25 of movies_controller.rb can be updated from ---def can_be_created_in_a_block(args = {})--- to ---def can_be_created_in_a_block(args = { __ })---
That's the area that needs to be updated to pass the 'can be created in a block when no args are passed' on line 72 of movie_spec.rb
This is a great candidate for just basic AR CRUD stuff.
Fork this lab, and remove all the references to the migrations. Just have it so that they set up the database, then hey look ALL THE MAGIC METHODS.
noticed that in the spec, Movie.new tests for the Matrix movie and lists movie.director = "The Wachowski Brothers"
Both Wachowskis have transitioned to female and are now the Wachowskis or the Wachowski Sisters.
Solution branch is not passing all tests.
PASSES:
def can_find_by_multiple_attributes
Movie.find_by(title: "Title")
end
In each method the __ corresponds to a line of code you will need to write to make the spec pass
There are different ways to solve this lab so feel free to experiment!
"You can use more than one line of code" - Justin Daniel, Technical Coach
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.