Last active
January 1, 2016 23:59
-
-
Save braidn/8220389 to your computer and use it in GitHub Desktop.
Rspec Attempt On Gift Change
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 Quarterly | |
class GiftIssueToggle | |
def initialize(issue) | |
@issue = issue | |
clear_gifts_for_plan | |
end | |
def set_current | |
Quarterly::Issue.find(@issue.id).update_attribute(:gift, true) | |
end | |
private | |
attr_reader :issue | |
def clear_gifts_for_plan | |
Quarterly::SubscriptionPlan.find(issue.plan.id).issues.each do |issue| | |
issue.update_attribute(:gift, false) | |
end | |
end | |
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 'spec_helper' | |
module Quarterly | |
describe GiftIssueToggle do | |
let(:issue) { create(:issue) } | |
subject { GiftIssueToggle.new(issue) } | |
it 'modifies issue.gift boolean if #set_current called' do | |
expect(subject.set_current).to change(issue.gift).from(false).to(true) | |
end | |
context 'when a previous item is a gift' do | |
let(:gift_issue) { create(:issue, plan: issue.plan, gift: true) } | |
it 'will zero out true gifts on creation' do | |
expect(subject).to change(gift_issue.gift).from(true).to(false) | |
end | |
end | |
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
.FF | |
Failures: | |
1) Quarterly::GiftIssueToggle modifys the gift boolean flag if #set_current called | |
Failure/Error: expect(subject.set_current).to change(issue.gift).from(false).to(true) | |
TypeError: | |
nil is not a symbol | |
# ./spec/models/quarterly/gift_issue_toggle_spec.rb:14:in `block (2 levels) in <module:Quarterly>' | |
# -e:1:in `<main>' | |
2) Quarterly::GiftIssueToggle when a previous item is a gift will zero out true gifts on creation | |
Failure/Error: expect(subject).to change(gift_issue.gift).from(true).to(false) | |
TypeError: | |
nil is not a symbol | |
# ./spec/models/quarterly/gift_issue_toggle_spec.rb:21:in `block (3 levels) in <module:Quarterly>' | |
# -e:1:in `<main>' | |
Finished in 2.62 seconds | |
3 examples, 2 failures | |
Failed examples: | |
rspec ./spec/models/quarterly/gift_issue_toggle_spec.rb:13 # Quarterly::GiftIssueToggle modifys the gift boolean flag if #set_current called | |
rspec ./spec/models/quarterly/gift_issue_toggle_spec.rb:20 # Quarterly::GiftIssueToggle when a previous item is a gift will zero out true gifts on creation | |
Randomized with seed 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment