Skip to content

Instantly share code, notes, and snippets.

@ktusznio
Last active December 11, 2015 04:58
Show Gist options
  • Save ktusznio/4549171 to your computer and use it in GitHub Desktop.
Save ktusznio/4549171 to your computer and use it in GitHub Desktop.
def available_if_enough_info
if self.available? || self.display_only?
if self.can_be_available?
self.available!
else
self.display_only!
end
end
end
describe "#available_if_enough_info" do
let(:have) { FactoryGirl.build_stubbed(:have, status: status) }
shared_examples_for "available and display only haves" do
let(:can_be_available?) { true }
before(:each) do
have.stubs(:can_be_available?).returns(can_be_available?)
have.available_if_enough_info
end
context "can't be available" do
let(:can_be_available?) { false }
it "marks the have as display only" do
have.display_only?.should be_true
end
end
context "can be available" do
it "marks the have as available" do
have.available?.should be_true
end
end
end
context "status is available" do
let(:status) { :available }
it_behaves_like "available and display only haves"
end
context "status is display only" do
let(:status) { :display_only }
it_behaves_like "available and display only haves"
end
context "status is something else" do
let(:status) { :pending }
it "doesn't change the status" do
have.available_if_enough_info
have.status.should == status
end
end
end
describe "#available_if_enough_info" do
let(:have) { FactoryGirl.build_stubbed(:have, status: status) }
shared_examples_for "available and display-only haves" do
it "marks the have as display only when it can't be available" do
have.stubs(can_be_available?: false)
have.available_if_enough_info
have.display_only?.should be_true
end
it "marks the have as available when it can be available" do
have.stubs(can_be_available?: true)
have.available_if_enough_info
have.available?.should be_true
end
end
context "status is available" do
let(:status) { :available }
it_behaves_like "available and display-only haves"
end
context "status is display only" do
let(:status) { :display_only }
it_behaves_like "available and display-only haves"
end
context "status is something else" do
let(:status) { :pending }
it "doesn't change the status" do
have.available_if_enough_info
have.status.should == status
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment