public
Last active

  • Download Gist
gistfile1.rbx
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
# Example of how to test a module included into multiple models
 
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
 
describe Featurable do
class FeaturableObject
include Featurable
 
attr_accessor :sport, :featured_at
 
def featured_at?
!@featured_at.nil?
end
end
 
before :each do
@featurable = FeaturableObject.new
end
 
describe "can_be_featured_by?" do
context "user is an admin" do
before :each do
@user = stub_model(User, :admin? => true)
end
 
it "should return true if assigned to a sport" do
@featurable.sport = stub_model(Sport)
@featurable.can_be_featured_by?(@user).should be_true
end
 
it "should return false if not assigned to a sport" do
@featurable.sport = nil
@featurable.can_be_featured_by?(@user).should be_false
end
end
 
context "user is not an admin" do
it "should return false" do
user = stub_model(User, :admin? => false)
@featurable.can_be_featured_by?(user).should be_false
end
end
end
 
describe "featured?" do
specify do
@featurable.featured_at = Time.now
@featurable.should be_featured
end
 
specify do
@featurable.featured_at = nil
@featurable.should_not be_featured
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.