Sha256: 64f90d0541e6635d5a25f4ebb12608a3db718ee45c13f37485544a63869b1ce2

Contents?: true

Size: 1.77 KB

Versions: 12

Compression:

Stored size: 1.77 KB

Contents

shared_examples "#squash_many_duplicates" do |model|
  before do
    @master = FactoryGirl.create(model, title: "master")
    @dup1 = FactoryGirl.create(model, title: "dup1")
    @dup2 = FactoryGirl.create(model, title: "dup2")
  end

  context "happy path" do
    before do
      post :squash_many_duplicates, master_id: @master.id, duplicate_id_1: @dup1.id, duplicate_id_2: @dup2.id
    end

    it "squashes the duplicates into the master" do
      expect(@master.duplicate_ids).to match_array([@dup1.id, @dup2.id])
    end

    it "redirects to duplicates page for more duplicate squashing" do
      expect(response).to redirect_to("/#{model}s/duplicates")
    end

    it "sets the flash success message" do
      expect(flash[:success]).to eq(%(Squashed duplicate #{model}s ["dup1", "dup2"] into master #{@master.id}.))
    end
  end

  context "with no master" do
    it "redirects with a failure message" do
      post :squash_many_duplicates, duplicate_id_1: @dup1.id, duplicate_id_2: @dup2.id
      expect(flash[:failure]).to eq("A master #{model} must be selected.")
      expect(response).to redirect_to("/#{model}s/duplicates")
    end
  end

  context "with no duplicates" do
    it "redirects with a failure message" do
      post :squash_many_duplicates, master_id: @master.id
      expect(flash[:failure]).to eq("At least one duplicate #{model} must be selected.")
      expect(response).to redirect_to("/#{model}s/duplicates")
    end
  end

  context "with duplicates containing master" do
    it "redirects with a failure message" do
      post :squash_many_duplicates, master_id: @master.id, duplicate_id_1: @master.id
      expect(flash[:failure]).to eq("The master #{model} could not be squashed into itself.")
      expect(response).to redirect_to("/#{model}s/duplicates")
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
grokus-1.0.0.9 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.8 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.7 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.6 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.5 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.3 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.2 spec/controllers/squash_many_duplicates_examples.rb
grokus-1.0.0.1 spec/controllers/squash_many_duplicates_examples.rb
calagator-1.0.0.rc3 spec/controllers/squash_many_duplicates_examples.rb
calagator-1.0.0.rc2 spec/controllers/squash_many_duplicates_examples.rb
calagator-1.0.0.rc1 spec/controllers/squash_many_duplicates_examples.rb
calagator-0.0.1.pre1 spec/controllers/squash_many_duplicates_examples.rb