test/test_helper.rb in set_builder-2.0.0.beta2 vs test/test_helper.rb in set_builder-2.0.0.beta3

- old
+ new

@@ -1,47 +1,51 @@ require "rubygems" require "rails" require "rails/test_help" require "active_support/core_ext" require "set_builder" +require "shoulda/context" require "pry" require "support/fake_connection" +require "timecop" require "minitest/reporters" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Sample class used by tests SetBuilder::ValueMap.register(:school, [[1, "Concordia"], [2, "McKendree"]]) +friends = Arel::Table.new(:friends) + $friend_traits = SetBuilder::Traits.new do - trait('who are [not] "awesome"') do |query, scope| + trait('who [are|are not] "awesome"') do |query, scope| scope << {:conditions => {:awesome => true}} end - trait('who [have not] "died"') do |query, scope| + trait('who [have|have not] "died"') do |query, scope| scope << {:conditions => {:alive => false}} end trait('who were "born" <date>') do |query, scope| - scope << {:conditions => query.modifiers[0].build_conditions_for("friends.birthday")} + scope << {:conditions => query.modifiers[0].build_arel_for(friends[:birthday]).to_sql} end trait('whose "age" <number>') do |query, scope| - scope << {:conditions => query.modifiers[0].build_conditions_for("friends.age")} + scope << {:conditions => query.modifiers[0].build_arel_for(friends[:age]).to_sql} end - trait('who have [not] "attended" :school') do |query, scope| + trait('who [have|have not] "attended" :school') do |query, scope| scope << { :joins => "INNER JOIN schools ON friends.school_id=schools.id", :conditions => {"schools.id" => query.direct_object} } end trait('whose "name" <string>') do |query, scope| - scope << {:conditions => query.modifiers[0].build_conditions_for("friends.name")} + scope << {:conditions => query.modifiers[0].build_arel_for(friends[:name]).to_sql} end end class Friend @@ -51,19 +55,17 @@ [] end # Stubs so that Arel can SQL + class << self + attr_accessor :connection_pool - attr_accessor :connection_pool - - def initialize - @connection_pool = Fake::ConnectionPool.new + def connection + connection_pool.connection + end end + @connection_pool = Fake::ConnectionPool.new - def connection - connection_pool.connection - end - end -Arel::Table.engine = Arel::Sql::Engine.new(Friend.new) +Arel::Table.engine = Friend