Skip to content

Instantly share code, notes, and snippets.

@tonatiuh
Created September 22, 2012 01:39
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 tonatiuh/3764818 to your computer and use it in GitHub Desktop.
Save tonatiuh/3764818 to your computer and use it in GitHub Desktop.
Update another record on after_save on model
after_save :bid_adjusts
def bid_adjusts
unless @old_exclusive_campaign.nil?
campaign = Campaign.find(@old_exclusive_campaign.id)
campaign.update_attributes(exclusivity: false)
campaign.save
end
end
@antillas21
Copy link

describe "once an exclusive campaign is created" do
  context "takes over exclusivity from an old campaign" do
    let(:old_campaign) { FactoryGirl.create(:campaign_exclusive, :name => "Old Exclusive", :bid => 3) }

    it "should set to false the exclusivity field of old campaign", run: true do
      FactoryGirl.create(:campaign_exclusive, bid: 4)
      # may or may not need to do old_campaign.reload
      old_campaign.exclusivity.should be_false
    end
  end
end

I don't know if you need to reload the old_campaign object... as we're using let

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment