Sha256: 88dbd2a9dd15326822ab72e82895371104654e9ee22c8fdf4f78f2ee3bef818d

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

require_relative 'test_helper'
require 'erb'
require 'active_record'

ActiveRecord::Base.logger         = SemanticLogger[ActiveRecord]
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read('test/config/database.yml')).result)
ActiveRecord::Base.establish_connection(:test)

ActiveRecord::Schema.define :version => 0 do
  create_table :people, :force => true do |t|
    t.string :name
    t.string :state
    t.string :zip_code
  end
end

class Person < ActiveRecord::Base
end

class MinionScopeTest < Minitest::Test
  describe ParallelMinion::Minion do
    [false, true].each do |enabled|
      describe ".new with enabled: #{enabled.inspect}" do
        before do
          Person.create(name: 'Jack', state: 'FL', zip_code: 38729)
          Person.create(name: 'John', state: 'FL', zip_code: 35363)
          Person.create(name: 'Jill', state: 'FL', zip_code: 73534)
          Person.create(name: 'Joe', state: 'NY', zip_code: 45325)
          Person.create(name: 'Jane', state: 'NY', zip_code: 45325)
          Person.create(name: 'James', state: 'CA', zip_code: 123123)
          # Instruct Minions to adhere to any dynamic scopes for Person model
          ParallelMinion::Minion.scoped_classes << Person
          ParallelMinion::Minion.enabled = enabled
        end

        after do
          Person.destroy_all
          ParallelMinion::Minion.scoped_classes.clear
          SemanticLogger.flush
        end

        it 'copy across model scope' do
          assert_equal 6, Person.count

          Person.unscoped.where(state: 'FL').scoping { Person.count }

          Person.unscoped.where(state: 'FL').scoping do
            assert_equal 3, Person.count
            minion = ParallelMinion::Minion.new(description: 'Scope Test', log_exception: :full) do
              Person.count
            end
            assert_equal 3, minion.result
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parallel_minion-1.2.1 test/minion_scope_test.rb