spec: get acts_as_list tests running again
test plan: check jenkins output confirm it runs now Change-Id: I25c9e677ae754e1cfcb9562aef6585ff6e40b0b7 Reviewed-on: https://gerrit.instructure.com/107796 Tested-by: Jenkins Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Product-Review: Landon Wilkins <lwilkins@instructure.com> QA-Review: Landon Wilkins <lwilkins@instructure.com>
This commit is contained in:
parent
cb53fc0b26
commit
2f90c122fe
|
@ -59,7 +59,7 @@ module ActiveRecord
|
|||
when Hash
|
||||
scope
|
||||
else
|
||||
raise InvalidArgument.new("scope must be nil, a symbol, an array, or a hash")
|
||||
raise ArgumentError.new("scope must be nil, a symbol, an array, or a hash")
|
||||
end
|
||||
# expand assocations to their foreign keys
|
||||
new_scope = {}
|
||||
|
@ -126,9 +126,7 @@ module ActiveRecord
|
|||
RUBY
|
||||
|
||||
if position_column != 'position'
|
||||
class_eval do
|
||||
alias_method :position, self.class.position_column.to_sym
|
||||
end
|
||||
define_method(:position) { read_attribute(self.class.position_column.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
require 'active_record/acts/list'
|
||||
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::List }
|
||||
require_relative "active_record/acts/list"
|
||||
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::List }
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
bundle check || bundle install
|
||||
ruby test/list_test.rb
|
|
@ -1,12 +1,11 @@
|
|||
require 'test/unit'
|
||||
|
||||
require 'rubygems'
|
||||
gem 'activerecord', '>= 1.15.4.7794'
|
||||
require 'active_record'
|
||||
|
||||
require "#{File.dirname(__FILE__)}/../init"
|
||||
require_relative "../lib/acts_as_list"
|
||||
|
||||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
||||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
||||
|
||||
def setup_db
|
||||
ActiveRecord::Schema.define(:version => 1) do
|
||||
|
@ -26,12 +25,13 @@ def teardown_db
|
|||
end
|
||||
|
||||
class Mixin < ActiveRecord::Base
|
||||
def self.nulls(first_or_last, column, direction = nil)
|
||||
"#{column} IS#{" NOT" unless first_or_last == :last} NULL, #{column} #{direction.to_s.upcase}".strip
|
||||
end
|
||||
end
|
||||
|
||||
class ListMixin < Mixin
|
||||
acts_as_list :column => "pos", :scope => :parent
|
||||
|
||||
def self.table_name() "mixins" end
|
||||
acts_as_list :column => "pos", :scope => :parent_id
|
||||
end
|
||||
|
||||
class ListMixinSub1 < ListMixin
|
||||
|
@ -40,13 +40,10 @@ end
|
|||
class ListMixinSub2 < ListMixin
|
||||
end
|
||||
|
||||
class ListWithStringScopeMixin < ActiveRecord::Base
|
||||
acts_as_list :column => "pos", :scope => 'parent_id = #{parent_id}'
|
||||
|
||||
def self.table_name() "mixins" end
|
||||
class UnscopedListMixin < Mixin
|
||||
acts_as_list :column => "pos"
|
||||
end
|
||||
|
||||
|
||||
class ListTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
|
@ -82,7 +79,7 @@ class ListTest < Test::Unit::TestCase
|
|||
|
||||
def test_injection
|
||||
item = ListMixin.new(:parent_id => 1)
|
||||
assert_equal "parent_id = 1", item.scope_condition
|
||||
assert_equal({parent_id: 1}, item.scope_condition)
|
||||
assert_equal "pos", item.class.position_column
|
||||
end
|
||||
|
||||
|
@ -155,24 +152,16 @@ class ListTest < Test::Unit::TestCase
|
|||
assert_equal 3, ListMixin.find(4).pos
|
||||
|
||||
ListMixin.find(1).destroy
|
||||
|
||||
assert_equal [3, 4], ListMixin.where('parent_id = 5').order('pos').pluck(:id)
|
||||
|
||||
assert_equal 1, ListMixin.find(3).pos
|
||||
assert_equal 2, ListMixin.find(4).pos
|
||||
end
|
||||
|
||||
def test_with_string_based_scope
|
||||
new = ListWithStringScopeMixin.create(:parent_id => 500)
|
||||
assert_equal 1, new.pos
|
||||
assert new.first?
|
||||
assert new.last?
|
||||
end
|
||||
|
||||
def test_nil_scope
|
||||
new1, new2, new3 = ListMixin.create, ListMixin.create, ListMixin.create
|
||||
new1, new2, new3 = UnscopedListMixin.create, UnscopedListMixin.create, UnscopedListMixin.create
|
||||
new2.move_to_top
|
||||
assert_equal [new2, new1, new3], ListMixin.where('parent_id IS NULL').order('pos').to_a
|
||||
assert_equal [new2, new1, new3], UnscopedListMixin.where('parent_id IS NULL').order('pos').to_a
|
||||
end
|
||||
|
||||
|
||||
|
@ -245,7 +234,7 @@ class ListSubTest < Test::Unit::TestCase
|
|||
|
||||
def test_injection
|
||||
item = ListMixin.new("parent_id"=>1)
|
||||
assert_equal "parent_id = 1", item.scope_condition
|
||||
assert_equal({parent_id: 1}, item.scope_condition)
|
||||
assert_equal "pos", item.class.position_column
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue