<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - 8.2 Restricting by scope Problem using scope]]></title>
		<link>http://railsforum.com/viewtopic.php?id=51847</link>
		<description><![CDATA[The most recent posts in 8.2 Restricting by scope Problem using scope.]]></description>
		<lastBuildDate>Fri, 04 Jan 2013 05:46:05 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[8.2 Restricting by scope Problem using scope]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=158024#p158024</link>
			<description><![CDATA[<p>Hi,</p><p>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:</p><p>In my \features\step_definitions\permission_steps.rb I have:</p><p>Given /^&quot;([^&quot;]*)&quot; can view the &quot;([^&quot;]*)&quot; project$/ do |user, project|<br />Permission.create!(:user =&gt; User.find_by_email!(user),<br />:thing =&gt; Project.find_by_name!(project),<br />:action =&gt; &quot;view&quot;)<br />end</p><p>In my \app\models\project.rb I have:</p><p>scope :readable_by, lambda { |user|<br />joins(:permissions).where(:permissions =&gt; { :action =&gt; &quot;view&quot;,<br />:user_id =&gt; user.id })<br />}</p><br /><p>My \features\viewing_projects.feature:</p><p>Feature: Viewing projects<br />In order to assign tickets to a project<br />As a user<br />I want to be able to see a list of available projects</p><p>Background:<br />Given there are the following users:<br />| email | password |<br />| user@ticketee.com | password |<br />And I am signed in as them<br />And there is a project called &quot;TextMate 2&quot;<br />And &quot;user@ticketee.com&quot; can view the &quot;TextMate 2&quot; project</p><p>Scenario: Listing all projects<br />And I am on the homepage<br />When I follow &quot;TextMate 2&quot;<br />Then I should be on the project page for &quot;TextMate 2&quot;</p><p>When I run bin/cucumber features/viewing_projects.feature:</p><p>I got:</p><p>Then I should be on the project page for &quot;TextMate 2&quot; # features/step_de<br />finitions/web_steps.rb:233<br />expected: &quot;/projects/1&quot;<br />got: &quot;/projects&quot; (using ==) (RSpec::Expectations::ExpectationNotMetEr<br />ror)<br />./features/step_definitions/web_steps.rb:236:in `/^(?:|I )should be on (.+<br />)$/&#039;<br />features\viewing_projects.feature:17:in `Then I should be on the project p<br />age for &quot;TextMate 2&quot;&#039;</p><p>Failing Scenarios:<br />cucumber features\viewing_projects.feature:14 # Scenario: Listing all projects</p><br /><p>My \app\controllers\projects_controller.rb#find_project:<br />private<br />def find_project<br />@project = Project.readable_by(current_user).find(params[:id])<br />rescue ActiveRecord::RecordNotFound <br />flash[:alert] = &quot;The project you were looking&quot; +<br />&quot; for could not be found.&quot;<br />redirect_to projects_path</p><br /><p>end</p><p>So it&#039;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.</p><p>I am using rails 3.2.8 and ruby ruby 1.9.3p125 (2012-02-16)<br />The book I am using has this Pub. Date: September 28, 2011</p><p>Please help!</p><p>Thanks!</p><p><a href="http://www.30for50.com/en/">Wholesale Jewelry</a></p>]]></description>
			<author><![CDATA[dummy@example.com (adamwatsn)]]></author>
			<pubDate>Fri, 04 Jan 2013 05:46:05 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=158024#p158024</guid>
		</item>
	</channel>
</rss>
