Created — forked from jwo/burrito_delicious_policy.rb

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Fast Rails Burro Test -- Modules

View burrito_delicious_policy.rb
1 2 3 4 5 6
class BurritoDeliciousPolicy
 
def delicious?(burrito)
burrito.guacamole?
end
end
View burrito_delicious_policy.rb
1 2 3 4 5 6 7 8 9 10 11 12 13
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
View burrito_delicious_policy.rb
1 2 3 4
class Burro < ActiveRecord::Base
include Deliciousness
# boolean guacamole defined in schema
end
View burrito_delicious_policy.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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
View burrito_delicious_policy.rb
1 2 3 4 5 6 7
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
Something went wrong with that request. Please try again.