test/test_helper.rb in set_builder-1.1.0 vs test/test_helper.rb in set_builder-1.2.0.beta1
- old
+ new
@@ -5,74 +5,53 @@
require "turn"
require 'set_builder'
-# Mocks NamedScope so that composed scoping can be tested
-
-class FakeScope
-
- def initialize(args)
- args = [args] unless args.is_a?(Array)
- @composed_scope = args
- end
-
- def scoped(args)
- FakeScope.new(@composed_scope + [args])
- end
-
- def composed_scope
- @composed_scope
- end
-
-end
-
-
-
# Sample class used by tests
SetBuilder::ValueMap.register(:school, [[1, "Concordia"], [2, "McKendree"]])
class Friend
extend SetBuilder
- trait(:is, "awesome") do |query|
- {:conditions => {:awesome => true}}
+ trait(:is, "awesome") do |query, scope|
+ scope << {:conditions => {:awesome => true}}
end
- trait(nil, "died") do |query|
- {:conditions => {:alive => false}}
+ trait(nil, "died") do |query, scope|
+ scope << {:conditions => {:alive => false}}
end
# this trait accepts modifiers --- an adverbial clause
- trait(:was, "born", :date) do |query|
- {:conditions => query.modifiers[0].build_conditions_for("friends.birthday")}
+ trait(:was, "born", :date) do |query, scope|
+ scope << {:conditions => query.modifiers[0].build_conditions_for("friends.birthday")}
end
- trait(:whose, "age", :number) do |query|
- {:conditions => query.modifiers[0].build_conditions_for("friends.age")}
+ trait(:whose, "age", :number) do |query, scope|
+ scope << {:conditions => query.modifiers[0].build_conditions_for("friends.age")}
end
# this trait has a direct object
- trait(:has, {"attended" => :school}) do |query|
- {
+ trait(:has, {"attended" => :school}) do |query, scope|
+ scope << {
:joins => "INNER JOIN schools ON friends.school_id=schools.id",
:conditions => {"schools.id" => query.direct_object}
}
end
# this trait is a noun
# also modifiers can be classes
- trait(:whose, "name", StringModifier) do |query|
- {:conditions => query.modifiers[0].build_conditions_for("friends.name")}
+ trait(:whose, "name", StringModifier) do |query, scope|
+ scope << {:conditions => query.modifiers[0].build_conditions_for("friends.name")}
end
# by stubbing out scoped, we can unit test the `performed` features
- def self.scoped(*args)
- FakeScope.new(args)
+ def self.to_scope
+ []
end
end
\ No newline at end of file