Sha256: b46b871da0cc6a2662d5b606346069662c482aca5e77f91ae1ae8bd5129f97be

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require "spec_helper"

describe Detour::OptOutFlag do
  it { should be_a Detour::Flag }
  it { should belong_to :flaggable }
  it { should validate_presence_of :flaggable }
  it { should allow_mass_assignment_of :flaggable }

  it "validates uniquness of feature_id on flaggable" do
    user  = create :user
    flag  = create :opt_out_flag, flaggable: user
    flag2 = build  :opt_out_flag, flaggable: user, feature: flag.feature

    flag2.should_not be_valid
    flag2.errors.full_messages.should eq ["Feature has already been taken"]
  end

  describe "when creating" do
    let(:flag) { create :opt_out_flag }

    it "increments its feature's opt_out_count" do
      flag.reload.feature.opt_out_count_for(flag.flaggable_type.tableize).should eq 1
    end
  end

  describe "when destroying" do
    let!(:flag)  { create  :opt_out_flag }
    let!(:flag2) { create  :opt_out_flag, feature: flag.feature }

    before do
      flag2.destroy
    end

    it "decrements its feature's opt_out_count" do
      flag.reload.feature.opt_out_count_for(flag.flaggable_type.tableize).should eq 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
detour-0.0.3 spec/models/detour/opt_out_flag_spec.rb
detour-0.0.2 spec/models/detour/opt_out_flag_spec.rb