Sha256: 0841a6b32134e09bdfd568eaf3430b8747e4dded9b29d68fa89a5e31e917a353

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require "spec_helper"

describe Detour::ActsAsFlaggable do
  subject { User.new }

  it { should have_many :flag_in_flags }
  it { should have_many :opt_out_flags }
  it { should have_many(:features).through(:flag_in_flags) }

  it "includes Detour::Flaggable" do
    subject.class.ancestors.should include Detour::Flaggable
  end

  describe "#acts_as_flaggable" do
    describe "Detour::Feature associations" do
      subject { Detour::Feature.new }
      it { should have_many(:users_group_flags).class_name("Detour::GroupFlag").dependent(:destroy) }
      it { should allow_mass_assignment_of(:users_group_flags_attributes) }
      it { should accept_nested_attributes_for(:users_group_flags) }

      it { should have_one(:users_percentage_flag).class_name("Detour::PercentageFlag").dependent(:destroy) }
      it { should allow_mass_assignment_of(:users_percentage_flag_attributes) }
      it { should accept_nested_attributes_for(:users_percentage_flag) }

      it { should have_many(:users_flag_ins).class_name("Detour::FlagInFlag").dependent(:destroy) }
      it { should have_many(:users_opt_outs).class_name("Detour::OptOutFlag").dependent(:destroy) }
    end

    context "when given a :find_by parameter" do
      class Foo < ActiveRecord::Base
        acts_as_flaggable find_by: :email
      end

      it "sets the appropriate class variable on the class" do
        Foo.instance_variable_get("@detour_flaggable_find_by").should eq :email
      end
    end

    context "when not given a :find_by parameter" do
      it "uses the default :id value for flaggable_find_by" do
        User.instance_variable_get("@detour_flaggable_find_by").should eq :id
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
detour-0.0.3 spec/lib/detour/acts_as_flaggable_spec.rb
detour-0.0.2 spec/lib/detour/acts_as_flaggable_spec.rb