Sha256: 547b00e7e3623129b51b7d7d50eb02fb78080ce7b54b87d9462f59e56e2887c7

Contents?: true

Size: 1.71 KB

Versions: 38

Compression:

Stored size: 1.71 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class HaveNamedScopeMatcherTest < ActiveSupport::TestCase # :nodoc:

  context "an attribute with a named scope" do
    setup do
      define_model :example, :attr => :string do
        named_scope :xyz, lambda {|n|
          { :order => :attr }
        }
      end
      @model = Example.new
    end

    should "accept having a scope with the correct signature" do
      assert_accepts have_named_scope("xyz(1)"), @model
    end

    should "accept having a scope with the correct signature and find options" do
      assert_accepts have_named_scope("xyz(1)").finding(:order => :attr), @model
    end
    
    should "reject having a scope with incorrect find options" do
      assert_rejects have_named_scope("xyz(1)").
                       finding(:order => 'attr DESC'),
                     @model
    end
    
    should "reject having a scope with another name" do
      assert_rejects have_named_scope("abc(1)"), @model
    end

  end

  should "evaluate the scope in the correct context" do
    define_model :example, :attr => :string do
      named_scope :xyz, lambda {|n|
        { :order => n }
      }
    end
    model = Example.new
    @order = :attr
    assert_accepts have_named_scope("xyz(@order)").
                     finding(:order => @order).
                     in_context(self),
                   model
  end

  context "a method that does not return a scope" do
    setup do
      klass = Class.new
      klass.class_eval do
        def self.xyz
          'xyz'
        end
      end
      @model = klass.new
    end

    should "reject having a named scope with that name" do
      assert_rejects have_named_scope(:xyz), @model
    end
  end

end

Version data entries

38 entries across 38 versions & 10 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.1 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.10 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.11 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.12 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.13 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.14 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.15 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.16 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.17 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.2 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.3 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.4 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.5 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.6 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.7 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
auser-poolparty-1.3.8 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
fairchild-poolparty-1.3.17 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
fairchild-poolparty-1.3.5 vendor/gems/shoulda/test/matchers/active_record/have_named_scope_matcher_test.rb
iGEL-shoulda-2.10.2 test/matchers/active_record/have_named_scope_matcher_test.rb