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