Permalink
Browse files

Support for activerecord 3.1

  • Loading branch information...
1 parent 9cd005a commit 5f43d641546e7fcedabecb2ecbcc659bb4fc2e59 Brian Jones committed Dec 9, 2011
Showing with 22 additions and 11 deletions.
  1. +14 −10 lib/resort.rb
  2. +2 −1 resort.gemspec
  3. +6 −0 spec/spec_helper.rb
View
@@ -155,10 +155,10 @@ def prepend
if _siblings.count > 0
delete_from_list
old_first = _siblings.first_in_order
- self.update_attribute(:next_id, old_first.id)
- old_first.update_attribute(:first, false)
+ self.update_attribute(:next_id, old_first.id) || raise(RecordNotSaved)
+ old_first.update_attribute(:first, false) || raise(RecordNotSaved)
end
- self.update_attribute(:first, true)
+ self.update_attribute(:first, true) || raise(RecordNotSaved)
end
end
@@ -177,8 +177,12 @@ def append_to(another)
return if another.next_id == id
another.lock!
delete_from_list
- self.update_attribute(:next_id, another.next_id) if self.next_id or (another && another.next_id)
- another.update_attribute(:next_id, self.id) if another
+ if self.next_id or (another && another.next_id)
+ self.update_attribute(:next_id, another.next_id) || raise(RecordNotSaved)
+ end
+ if another
+ another.update_attribute(:next_id, self.id) || raise(RecordNotSaved)
+ end
end
end
@@ -187,16 +191,16 @@ def append_to(another)
def delete_from_list
if first? && self.next
self.next.lock!
- self.next.update_attribute(:first, true)
+ self.next.update_attribute(:first, true) || raise(RecordNotSaved)
elsif self.previous
self.previous.lock!
- self.previous.update_attribute(:next_id, self.next_id)
+ p = self.previous
+ self.previous = nil unless frozen?
+ p.update_attribute(:next_id, self.next_id) || raise(RecordNotSaved)
end
-
unless frozen?
self.first = false
self.next = nil
- self.previous = nil
save!
end
end
@@ -208,7 +212,7 @@ def last?
def last!
self.class.transaction do
self.lock!
- _siblings.last_in_order.update_attribute(:next_id, self.id)
+ _siblings.last_in_order.update_attribute(:next_id, self.id) || raise(RecordNotSaved)
end
end
View
@@ -14,7 +14,8 @@ Gem::Specification.new do |s|
s.rubyforge_project = "resort"
- s.add_runtime_dependency 'activerecord', '~> 3.0.5'
+ s.add_runtime_dependency 'activerecord', '>= 3.0.5', '< 3.2'
+# s.add_runtime_dependency 'activerecord', '~> 3.0.5'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec', '~> 2.5.0'
s.add_development_dependency 'yard'
View
@@ -1,6 +1,12 @@
require 'rspec'
module Rails
+ class << self
+ # 3.0 defaults this, 3.1 does not
+ def application
+ "application"
+ end
+ end
end
require 'resort'

0 comments on commit 5f43d64

Please sign in to comment.