how to apply Roles and rights in shoulda BDD

0 views
Skip to first unread message

skg

unread,
Jun 23, 2009, 11:41:23 PM6/23/09
to shoulda
Hi
I am planning to use Prawn gem for pdf generation in my
application .There is a link in my view "Generate PDF" That link is on
a page which shows a particular Ticket details There are various tabs
on them depending on the permission allowed to any person Means all
user wont seen all the tabs which contain different informations
regardng that ticket. And I would like to do this pdf generation in a
BDD manner Could anybody please help or give some hint to start this?I
have tried this approach for some other problems But not for with
roles ,rights and permissions all

sk

François Beausoleil

unread,
Jun 24, 2009, 7:45:27 AM6/24/09
to sho...@googlegroups.com
Using rights and permissions isn't really any different than doing
anything else. You setup your context, call something and verify that
everything went according to plan. The important thing is always to
try both sides of the coin: when you do have the permission, and when
you dont.

context "Given a user" do
setup do
@user = Factory(:user)
end

context "with the 'download_pdf' permission" do
setup do
@user.authorize :download_pdf
end

context "on GET to :show, :format => 'pdf'" do
setup do
get :show, :format => "pdf"
end

should_respond_with :success

should "provide a PDF for download" do
assert_match /download/, @response.headers["Content-
Disposition"]
end

should "name the PDF" do
assert_match /filename.pdf/, @response.headers["Content-
Disposition"]
end
end
end

context "on GET to :show, :format => 'pdf'" do
setup do
get :show, :format => "pdf"
end

should_respond_with :unauthorized
should_set_the_flash_to /not authorized to download/
end
end

Or something along those lines.

Hope that helps!
--
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/
Reply all
Reply to author
Forward
0 new messages