Created
October 12, 2011 12:13
-
-
Save jwo/1281064 to your computer and use it in GitHub Desktop.
Fast Rails Burro Test -- Modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BurritoDeliciousPolicy | |
def delicious?(burrito) | |
burrito.guacamole? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Burro < ActiveRecord::Base | |
include Deliciousness | |
# boolean guacamole defined in schema | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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