Skip to content

Instantly share code, notes, and snippets.

@shepmaster
Forked from steveklabnik/privacy_filter.rb
Created December 12, 2011 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shepmaster/1464813 to your computer and use it in GitHub Desktop.
Save shepmaster/1464813 to your computer and use it in GitHub Desktop.
A spec for a filter
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
require "app/models/privacy_filter"
describe PrivacyFilter do
let(:controller) do
mock("controller", :frist_post? => false,
:authenticate_administrator! => false,
:authenticate_user! => false)
end
it "allows access to the root article" do
# Note - changed to ask the controller, not poke at the params directly
controller.should_receive(:frist_post?)
PrivacyFilter.filter(controller)
end
it "allows access for administrators" do
controller.should_receive(:authenticate_administrator!)
PrivacyFilter.filter(controller)
end
it "allows access to users" do
controller.should_receive(:authenticate_user!)
PrivacyFilter.filter(controller)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment