-
-
Save dennyabraham/1464804 to your computer and use it in GitHub Desktop.
Revisions
-
dennyabraham revised this gist
Dec 12, 2011 . 1 changed file with 10 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,24 +2,23 @@ describe PrivacyFilter do let (:controller) { mock("controller", :authenticate_administrator! => nil, :authenticate_user! => nil, :params => {}) } it "allows access to the root article" do controller.stub!(:params => {:id => 1}) PrivacyFilter.filter(controller).should be_true end it "allows access for administrators" do controller.stub!(:authenticate_administrator! => true) PrivacyFilter.filter(controller).should be_true end it "allows access to users" do controller.stub!(:authenticate_user! => true) PrivacyFilter.filter(controller).should be_true end end -
steveklabnik created this gist
Dec 12, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ class PrivacyFilter class << self def filter(controller) @controller = controller first_article? or administrator? or user? end def first_article? @controller.params[:id] == 1 end def administrator? @controller.authenticate_administrator! end def user? @controller.authenticate_user! end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ require "app/models/privacy_filter" describe PrivacyFilter do before do PrivacyFilter.stub!(:first_article? => false, :administrator? => false, :user? => false) end it "allows access to the root article" do PrivacyFilter.unstub!(:first_article?) PrivacyFilter.filter(stub(:params => {:id => 1})).should be_true end it "allows access for administrators" do PrivacyFilter.unstub!(:administrator?) PrivacyFilter.filter(stub(:authenticate_administrator! => true)).should be_true end it "allows access to users" do PrivacyFilter.unstub!(:user?) PrivacyFilter.filter(stub(:authenticate_user! => true)).should be_true end end