rails2012 (1) [Avatar] Offline
#1
Hi,

I am new to ruby on rails. I have been following the book step by step. I solved the few problems by finding answers on the forum. But I am stuck at this, no solutions found:

In my featuresstep_definitionspermission_steps.rb I have:

Given /^"([^"]*)" can view the "([^"]*)" project$/ do |user, project|
Permission.create!(:user => User.find_by_email!(user),
:thing => Project.find_by_name!(project),
:action => "view"smilie
end

In my appmodelsproject.rb I have:

scope :readable_by, lambda { |user|
joins(:permissions).where(:permissions => { :action => "view",
:user_id => user.id })
}


My featuresviewing_projects.feature:

Feature: Viewing projects
In order to assign tickets to a project
As a user
I want to be able to see a list of available projects

Background:
Given there are the following users:
| email | password |
| user@ticketee.com | password |
And I am signed in as them
And there is a project called "TextMate 2"
And "user@ticketee.com" can view the "TextMate 2" project

Scenario: Listing all projects
And I am on the homepage
When I follow "TextMate 2"
Then I should be on the project page for "TextMate 2"

When I run bin/cucumber features/viewing_projects.feature:

I got:

Then I should be on the project page for "TextMate 2" # features/step_de
finitions/web_steps.rb:233
expected: "/projects/1"
got: "/projects" (using ==) (RSpec::Expectations::ExpectationNotMetEr
ror)
./features/step_definitions/web_steps.rb:236:in `/^(?smilieI )should be on (.+
)$/'
featuresviewing_projects.feature:17:in `Then I should be on the project p
age for "TextMate 2"'

Failing Scenarios:
cucumber featuresviewing_projects.feature:14 # Scenario: Listing all projects


My appcontrollersprojects_controller.rb#find_project:
private
def find_project
@project = Project.readable_by(current_user).find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:alert] = "The project you were looking" +
" for could not be found."
redirect_to projects_path


end

So it's either that the permission was not created (but if this is true I should see some errors right?) or the Scope is not finding the project.

I am using rails 3.2.8 and ruby ruby 1.9.3p125 (2012-02-16)
The book I am using has this Pub. Date: September 28, 2011

Please help!

Thanks!