The soon to be released Rails 4 in Action book by Ryan Bigg, Yehuda Katz and Steve Klabnik builds a ticketing/project management application in Ruby on Rails, from-the-ground-up, chapter-by-chapter. This repository is not my original work, but rather, me working throught the pre-release version of the book. Suggestions and issues with the pre-release noted below.
- The rvm use --default 1.9.3 should be rvm use --default ruby-1.9.3
- Suggestion : Would the use or mention of rvm gemsets be useful?
rvm gemset create rails4_0_0
rvm gemset use rails4_0_0
gem install rails -v 4.0.0
- 'The first line in this action sets up a new @purchase variable by calling the new method on the Product model, which initializes a new object of this model.' should be
- 'The first line in this action sets up a new @purchase variable by calling the new method on the Purchase model, which initializes a new object of this model.'
- The rspec-rails on the box on the top has version 2.13.2 where the text further below mentions 2.12
- Suggestion: Wouldn't it be better to run the /bin/rspec again and display the output before generating the model, as in previous steps?
Failure/Error: click_link 'New Project'
NameError:
uninitialized constant ProjectsController::Project
- Not huge issue, but Listing 3.1.6, missing closing p tag (and subsequent mentions of this same form)
- is gem 'factory_girl', '4.2.0' necessary when gem 'factory_girl-rails', '4.2.1' already on page 114? FGR depends on FG according to its gemspec
- Factory(:project, name: "TextMate 2") should be FactoryGirl.create(:project, name: "TextMate 2")
- Imbalanced quotation-marks on commit
- When generating models/migrations, that :string is default when not specified is already covered earlier in the book.
- user.authentication should be user.authenticate
- would be nice if a filename was given for the user signup spec. Based on earlier parts of book spec/features/creating_users_spec.rb
- nevermind, later on (page 177), it refers to this file as spec/features/signing_up_spec.rb - but still inconsistent from earlier parts of book
- which line in application.html.erb should nav tags go... not a biggie.
rm -rf spec/controllers
removes projects_controller_spec.rb which is something we added real specs to on page 132
- fill_in 'User Name', with: user.name should probably just be 'Name', either that or modify page 183
- @ticket.user.email (tickets and users may be related, and may be manually set on edit specs for example, but the relationship is never built during the create action in the ticket controller, which obviously causes failures in the following spec)
within "#ticket #author" do
expect(page).to have_content("Created by [email protected]")
end
- as above, 'User Name' does not exist, 'Name' does, same recommendations apply.
within("h2") { expect(page).to have_content("New Ticket") }
exists in the spec, but the show project page (the page the user would be on after signing in doesn't have this content)
- Author awknowledges that he forgot to write require_signin! method, and then says to use the following code to implement it, but includes no code. Here's what I wrote:
# application_controller.rb
private
def require_signin!
unless session[:user_id].present?
flash[:alert] = "You need to sign in or sign up before continuing."
redirect_to signin_path
end
end
- as above, 'User Name' does not exist, 'Name' does, same recommendations apply.
- Forgets to include the following spec created earlier, or include "..." probably as a result of PDF Page 175, rm -rf issue noted above.
it "displays an error for a missing project" do
get :show, :id => "not-here"
expect(response).to redirect_to(projects_path)
message = "The project you were looking for could not be found."
expect(flash[:alert]).to eql(message)
end
- Mentions "...Just like with the email_spec helper methods in the previous chapter..." which the reader hasn't created.
- current_user method called, but not created.
- talks about user_signed_in? method, but again, not created. Probably AWOL with the current_user method ;)
- Needs a password_confirmation field on the admin user form to pass. Also, need to use user_password user_password_confirmation to avoid ambiguity.
- DRY up code by moving all _form.html.erb error messages into a single partial
- Is there a reason why we do
textmate_2 = FactoryGirl.create(:project, name: "TextMate 2")
etc... rather than let!?
- requiring the button to say "Update Profile" may be a little too hard for new users given the partial already specifies <%= f.submit "Sign up" %>
- Personal opinion is that I think most new users would solve this problem by duplicating the code already in the _form partial.
- recommended approach, just use <%= f.submit %> in the partial and modify the sign_up spec and the profile spec to use "Create User" and "Update User"
- fwiw I solved it like this:
#users_helper.rb
def text_for_submit_button
if params[:action] == ("edit" || "update")
"Update Profile"
else
"Sign up"
end
end
# _form.html.erb
<%= f.submit text_for_submit_button %>