Skip to content

Instantly share code, notes, and snippets.

@garybernhardt
Created October 13, 2011 01:05
Show Gist options
  • Save garybernhardt/1283085 to your computer and use it in GitHub Desktop.
Save garybernhardt/1283085 to your computer and use it in GitHub Desktop.
require 'download_policy'
describe DownloadPolicy do
let(:screencast) { stub(:free? => false) }
let(:anonymous_user) { nil }
let(:user_with_access) { stub(:has_screencast_access? => true) }
let(:user_without_access) { stub(:has_screencast_access? => false) }
it "is disallowed for anonymous users" do
subject.allow_download_for?(screencast, anonymous_user).should be_false
end
it "is allowed for users who have download access" do
subject.allow_download_for?(screencast, user_with_access).should be_true
end
it "is disallowed for users who don't have access" do
subject.allow_download_for?(screencast, user_without_access).should be_false
end
it "is always allowed when the screencast is free" do
screencast = stub(:free? => true)
subject.allow_download_for?(screencast, user_without_access).should be_true
subject.allow_download_for?(screencast, user_with_access).should be_true
subject.allow_download_for?(screencast, anonymous_user).should be_true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment