Sha256: e773164f2809704eb8a3f9efdf19f734ebd6fbcf04d3ee57f9bbfdf5447a802e

Contents?: true

Size: 1.97 KB

Versions: 7

Compression:

Stored size: 1.97 KB

Contents

require "spec_helper"

describe Scenic::CommandRecorder do
  describe "#create_view" do
    it "records the created view" do
      recorder.create_view :greetings

      expect(recorder.commands).to eq [[:create_view, [:greetings], nil]]
    end

    it "reverts to drop_view" do
      recorder.revert { recorder.create_view :greetings }

      expect(recorder.commands).to eq [[:drop_view, [:greetings]]]
    end
  end

  describe "#drop_view" do
    it "records the dropped view" do
      recorder.drop_view :users

      expect(recorder.commands).to eq [[:drop_view, [:users], nil]]
    end

    it "reverts to create_view with specified revert_to_version" do
      args = [:users, { revert_to_version: 3 }]
      revert_args = [:users, { version: 3 }]

      recorder.revert { recorder.drop_view(*args) }

      expect(recorder.commands).to eq [[:create_view, revert_args]]
    end

    it "raises when reverting without revert_to_version set" do
      args = [:users, { another_argument: 1 }]

      expect { recorder.revert { recorder.drop_view(*args) } }
        .to raise_error(ActiveRecord::IrreversibleMigration)
    end
  end

  describe "#update_view" do
    it "records the updated view" do
      args = [:users, { version: 2 }]

      recorder.update_view(*args)

      expect(recorder.commands).to eq [[:update_view, args, nil]]
    end

    it "reverts to update_view with the specified revert_to_version" do
      args = [:users, { version: 2, revert_to_version: 1 }]
      revert_args = [:users, { version: 1 }]

      recorder.revert { recorder.update_view(*args) }

      expect(recorder.commands).to eq [[:update_view, revert_args]]
    end

    it "raises when reverting without revert_to_version set" do
      args = [:users, { version: 42, another_argument: 1 }]

      expect { recorder.revert { recorder.update_view(*args) } }
        .to raise_error(ActiveRecord::IrreversibleMigration)
    end
  end

  def recorder
    @recorder ||= ActiveRecord::Migration::CommandRecorder.new
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scenic-1.2.0 spec/scenic/command_recorder_spec.rb
scenic-1.1.1 spec/scenic/command_recorder_spec.rb
scenic-1.1.0 spec/scenic/command_recorder_spec.rb
scenic-1.0.0 spec/scenic/command_recorder_spec.rb
scenic-0.3.0 spec/scenic/command_recorder_spec.rb
scenic-0.2.1 spec/scenic/command_recorder_spec.rb
scenic-0.2.0 spec/scenic/command_recorder_spec.rb