Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from jwo/burrito_delicious_policy.rb
Created October 12, 2011 15:50
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 kivanio/1281593 to your computer and use it in GitHub Desktop.
Save kivanio/1281593 to your computer and use it in GitHub Desktop.
Fast Rails Burro Test -- Modules
class BurritoDeliciousPolicy
def delicious?(burrito)
burrito.guacamole?
end
end
require_relative '../../app/models/burrito_delicious_policy'
describe BurritoDeliciousPolicy do
it "should be delicious when there is guac" do
subject.delicious?(stub( :guacamole? => true)).should be_true
end
it "should not de delicious without guac" do
subject.delicious?(stub( :guacamole? => false)).should be_false
end
end
class Burro < ActiveRecord::Base
include Deliciousness
# boolean guacamole defined in schema
end
require_relative '../../lib/deliciousness'
require_relative '../../app/models/burrito_delicious_policy'
class Burro
include Deliciousness
attr_accessor :guacamole
def guacamole?
true
end
end
describe Burro do
it "should tell the policy to decide if this is delicious" do
our_mock = mock BurritoDeliciousPolicy
our_mock.should_receive(:delicious?)
BurritoDeliciousPolicy.stub(:new => our_mock)
subject.delicious?
end
end
module Deliciousness
def delicious?
BurritoDeliciousPolicy.new.delicious?(self)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment