mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
update plugins: 2 are available as gems, 1 updated and removed yaml_db
Signed-off-by: Reinier Balt <lrbalt@gmail.com>
This commit is contained in:
parent
998c14fa71
commit
39a38a8f73
25 changed files with 32 additions and 1193 deletions
2
Gemfile
2
Gemfile
|
|
@ -10,6 +10,7 @@ gem "sanitize", "~>1.2.1"
|
|||
gem "rack", "1.1.0"
|
||||
gem "will_paginate", "~> 2.3.15"
|
||||
gem "has_many_polymorphs", "~> 2.13"
|
||||
gem "acts_as_list", "~>0.1.4"
|
||||
gem "aasm", "2.2.0"
|
||||
gem "actionwebservice", :git => "git://github.com/dejan/actionwebservice.git"
|
||||
gem "rubycas-client"
|
||||
|
|
@ -28,6 +29,7 @@ group :test do
|
|||
gem "hoe"
|
||||
gem "rspec-rails", "~>1.3.3"
|
||||
gem "thoughtbot-factory_girl"
|
||||
gem 'memory_test_fix', '~>0.1.3'
|
||||
end
|
||||
|
||||
group :selenium do
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ GEM
|
|||
activeresource (2.3.14)
|
||||
activesupport (= 2.3.14)
|
||||
activesupport (2.3.14)
|
||||
acts_as_list (0.1.4)
|
||||
bcrypt-ruby (2.1.4)
|
||||
builder (3.0.0)
|
||||
cgi_multipart_eof_fix (2.5.0)
|
||||
|
|
@ -50,6 +51,7 @@ GEM
|
|||
hpricot (0.8.4)
|
||||
httpclient (2.2.1)
|
||||
json (1.5.3)
|
||||
memory_test_fix (0.1.3)
|
||||
mongrel (1.1.5)
|
||||
cgi_multipart_eof_fix (>= 2.4)
|
||||
daemons (>= 1.0.3)
|
||||
|
|
@ -96,6 +98,7 @@ DEPENDENCIES
|
|||
ZenTest (>= 4.0.0)
|
||||
aasm (= 2.2.0)
|
||||
actionwebservice!
|
||||
acts_as_list (~> 0.1.4)
|
||||
bcrypt-ruby (~> 2.1.4)
|
||||
cucumber-rails (~> 0.3.0)
|
||||
database_cleaner (>= 0.5.0)
|
||||
|
|
@ -104,6 +107,7 @@ DEPENDENCIES
|
|||
highline (~> 1.5.0)
|
||||
hoe
|
||||
hpricot
|
||||
memory_test_fix (~> 0.1.3)
|
||||
mongrel
|
||||
rack (= 1.1.0)
|
||||
rails (~> 2.3.12)
|
||||
|
|
|
|||
23
vendor/plugins/acts_as_list/README
vendored
23
vendor/plugins/acts_as_list/README
vendored
|
|
@ -1,23 +0,0 @@
|
|||
ActsAsList
|
||||
==========
|
||||
|
||||
This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a +position+ column defined as an integer on the mapped database table.
|
||||
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
class TodoList < ActiveRecord::Base
|
||||
has_many :todo_items, :order => "position"
|
||||
end
|
||||
|
||||
class TodoItem < ActiveRecord::Base
|
||||
belongs_to :todo_list
|
||||
acts_as_list :scope => :todo_list
|
||||
end
|
||||
|
||||
todo_list.first.move_to_bottom
|
||||
todo_list.last.move_higher
|
||||
|
||||
|
||||
Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license
|
||||
3
vendor/plugins/acts_as_list/init.rb
vendored
3
vendor/plugins/acts_as_list/init.rb
vendored
|
|
@ -1,3 +0,0 @@
|
|||
$:.unshift "#{File.dirname(__FILE__)}/lib"
|
||||
require 'active_record/acts/list'
|
||||
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::List }
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
module ActiveRecord
|
||||
module Acts #:nodoc:
|
||||
module List #:nodoc:
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
end
|
||||
|
||||
# This +acts_as+ extension provides the capabilities for sorting and reordering a number of objects in a list.
|
||||
# The class that has this specified needs to have a +position+ column defined as an integer on
|
||||
# the mapped database table.
|
||||
#
|
||||
# Todo list example:
|
||||
#
|
||||
# class TodoList < ActiveRecord::Base
|
||||
# has_many :todo_items, :order => "position"
|
||||
# end
|
||||
#
|
||||
# class TodoItem < ActiveRecord::Base
|
||||
# belongs_to :todo_list
|
||||
# acts_as_list :scope => :todo_list
|
||||
# end
|
||||
#
|
||||
# todo_list.first.move_to_bottom
|
||||
# todo_list.last.move_higher
|
||||
module ClassMethods
|
||||
# Configuration options are:
|
||||
#
|
||||
# * +column+ - specifies the column name to use for keeping the position integer (default: +position+)
|
||||
# * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach <tt>_id</tt>
|
||||
# (if it hasn't already been added) and use that as the foreign key restriction. It's also possible
|
||||
# to give it an entire string that is interpolated if you need a tighter scope than just a foreign key.
|
||||
# Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt>
|
||||
def acts_as_list(options = {})
|
||||
configuration = { :column => "position", :scope => "1 = 1" }
|
||||
configuration.update(options) if options.is_a?(Hash)
|
||||
|
||||
configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/
|
||||
|
||||
if configuration[:scope].is_a?(Symbol)
|
||||
scope_condition_method = %(
|
||||
def scope_condition
|
||||
if #{configuration[:scope].to_s}.nil?
|
||||
"#{configuration[:scope].to_s} IS NULL"
|
||||
else
|
||||
"#{configuration[:scope].to_s} = \#{#{configuration[:scope].to_s}}"
|
||||
end
|
||||
end
|
||||
)
|
||||
else
|
||||
scope_condition_method = "def scope_condition() \"#{configuration[:scope]}\" end"
|
||||
end
|
||||
|
||||
class_eval <<-EOV
|
||||
include ActiveRecord::Acts::List::InstanceMethods
|
||||
|
||||
def acts_as_list_class
|
||||
::#{self.name}
|
||||
end
|
||||
|
||||
def position_column
|
||||
'#{configuration[:column]}'
|
||||
end
|
||||
|
||||
#{scope_condition_method}
|
||||
|
||||
before_destroy :remove_from_list
|
||||
before_create :add_to_list_bottom
|
||||
EOV
|
||||
end
|
||||
end
|
||||
|
||||
# All the methods available to a record that has had <tt>acts_as_list</tt> specified. Each method works
|
||||
# by assuming the object to be the item in the list, so <tt>chapter.move_lower</tt> would move that chapter
|
||||
# lower in the list of all chapters. Likewise, <tt>chapter.first?</tt> would return +true+ if that chapter is
|
||||
# the first in the list of all chapters.
|
||||
module InstanceMethods
|
||||
# Insert the item at the given position (defaults to the top position of 1).
|
||||
def insert_at(position = 1)
|
||||
insert_at_position(position)
|
||||
end
|
||||
|
||||
# Swap positions with the next lower item, if one exists.
|
||||
def move_lower
|
||||
return unless lower_item
|
||||
|
||||
acts_as_list_class.transaction do
|
||||
lower_item.decrement_position
|
||||
increment_position
|
||||
end
|
||||
end
|
||||
|
||||
# Swap positions with the next higher item, if one exists.
|
||||
def move_higher
|
||||
return unless higher_item
|
||||
|
||||
acts_as_list_class.transaction do
|
||||
higher_item.increment_position
|
||||
decrement_position
|
||||
end
|
||||
end
|
||||
|
||||
# Move to the bottom of the list. If the item is already in the list, the items below it have their
|
||||
# position adjusted accordingly.
|
||||
def move_to_bottom
|
||||
return unless in_list?
|
||||
acts_as_list_class.transaction do
|
||||
decrement_positions_on_lower_items
|
||||
assume_bottom_position
|
||||
end
|
||||
end
|
||||
|
||||
# Move to the top of the list. If the item is already in the list, the items above it have their
|
||||
# position adjusted accordingly.
|
||||
def move_to_top
|
||||
return unless in_list?
|
||||
acts_as_list_class.transaction do
|
||||
increment_positions_on_higher_items
|
||||
assume_top_position
|
||||
end
|
||||
end
|
||||
|
||||
# Removes the item from the list.
|
||||
def remove_from_list
|
||||
if in_list?
|
||||
decrement_positions_on_lower_items
|
||||
update_attribute position_column, nil
|
||||
end
|
||||
end
|
||||
|
||||
# Increase the position of this item without adjusting the rest of the list.
|
||||
def increment_position
|
||||
return unless in_list?
|
||||
update_attribute position_column, self.send(position_column).to_i + 1
|
||||
end
|
||||
|
||||
# Decrease the position of this item without adjusting the rest of the list.
|
||||
def decrement_position
|
||||
return unless in_list?
|
||||
update_attribute position_column, self.send(position_column).to_i - 1
|
||||
end
|
||||
|
||||
# Return +true+ if this object is the first in the list.
|
||||
def first?
|
||||
return false unless in_list?
|
||||
self.send(position_column) == 1
|
||||
end
|
||||
|
||||
# Return +true+ if this object is the last in the list.
|
||||
def last?
|
||||
return false unless in_list?
|
||||
self.send(position_column) == bottom_position_in_list
|
||||
end
|
||||
|
||||
# Return the next higher item in the list.
|
||||
def higher_item
|
||||
return nil unless in_list?
|
||||
acts_as_list_class.find(:first, :conditions =>
|
||||
"#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
|
||||
)
|
||||
end
|
||||
|
||||
# Return the next lower item in the list.
|
||||
def lower_item
|
||||
return nil unless in_list?
|
||||
acts_as_list_class.find(:first, :conditions =>
|
||||
"#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
|
||||
)
|
||||
end
|
||||
|
||||
# Test if this record is in a list
|
||||
def in_list?
|
||||
!send(position_column).nil?
|
||||
end
|
||||
|
||||
private
|
||||
def add_to_list_top
|
||||
increment_positions_on_all_items
|
||||
end
|
||||
|
||||
def add_to_list_bottom
|
||||
self[position_column] = bottom_position_in_list.to_i + 1
|
||||
end
|
||||
|
||||
# Overwrite this method to define the scope of the list changes
|
||||
def scope_condition() "1" end
|
||||
|
||||
# Returns the bottom position number in the list.
|
||||
# bottom_position_in_list # => 2
|
||||
def bottom_position_in_list(except = nil)
|
||||
item = bottom_item(except)
|
||||
item ? item.send(position_column) : 0
|
||||
end
|
||||
|
||||
# Returns the bottom item
|
||||
def bottom_item(except = nil)
|
||||
conditions = scope_condition
|
||||
conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
|
||||
acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC")
|
||||
end
|
||||
|
||||
# Forces item to assume the bottom position in the list.
|
||||
def assume_bottom_position
|
||||
update_attribute(position_column, bottom_position_in_list(self).to_i + 1)
|
||||
end
|
||||
|
||||
# Forces item to assume the top position in the list.
|
||||
def assume_top_position
|
||||
update_attribute(position_column, 1)
|
||||
end
|
||||
|
||||
# This has the effect of moving all the higher items up one.
|
||||
def decrement_positions_on_higher_items(position)
|
||||
acts_as_list_class.update_all(
|
||||
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} <= #{position}"
|
||||
)
|
||||
end
|
||||
|
||||
# This has the effect of moving all the lower items up one.
|
||||
def decrement_positions_on_lower_items
|
||||
return unless in_list?
|
||||
acts_as_list_class.update_all(
|
||||
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"
|
||||
)
|
||||
end
|
||||
|
||||
# This has the effect of moving all the higher items down one.
|
||||
def increment_positions_on_higher_items
|
||||
return unless in_list?
|
||||
acts_as_list_class.update_all(
|
||||
"#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column).to_i}"
|
||||
)
|
||||
end
|
||||
|
||||
# This has the effect of moving all the lower items down one.
|
||||
def increment_positions_on_lower_items(position)
|
||||
acts_as_list_class.update_all(
|
||||
"#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} >= #{position}"
|
||||
)
|
||||
end
|
||||
|
||||
# Increments position (<tt>position_column</tt>) of all items in the list.
|
||||
def increment_positions_on_all_items
|
||||
acts_as_list_class.update_all(
|
||||
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
|
||||
)
|
||||
end
|
||||
|
||||
def insert_at_position(position)
|
||||
remove_from_list
|
||||
increment_positions_on_lower_items(position)
|
||||
self.update_attribute(position_column, position)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
332
vendor/plugins/acts_as_list/test/list_test.rb
vendored
332
vendor/plugins/acts_as_list/test/list_test.rb
vendored
|
|
@ -1,332 +0,0 @@
|
|||
require 'test/unit'
|
||||
|
||||
require 'rubygems'
|
||||
gem 'activerecord', '>= 1.15.4.7794'
|
||||
require 'active_record'
|
||||
|
||||
require "#{File.dirname(__FILE__)}/../init"
|
||||
|
||||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
||||
|
||||
def setup_db
|
||||
ActiveRecord::Schema.define(:version => 1) do
|
||||
create_table :mixins do |t|
|
||||
t.column :pos, :integer
|
||||
t.column :parent_id, :integer
|
||||
t.column :created_at, :datetime
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def teardown_db
|
||||
ActiveRecord::Base.connection.tables.each do |table|
|
||||
ActiveRecord::Base.connection.drop_table(table)
|
||||
end
|
||||
end
|
||||
|
||||
class Mixin < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class ListMixin < Mixin
|
||||
acts_as_list :column => "pos", :scope => :parent
|
||||
|
||||
def self.table_name() "mixins" end
|
||||
end
|
||||
|
||||
class ListMixinSub1 < ListMixin
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
class ListTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
setup_db
|
||||
(1..4).each { |counter| ListMixin.create! :pos => counter, :parent_id => 5 }
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_db
|
||||
end
|
||||
|
||||
def test_reordering
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).move_lower
|
||||
assert_equal [1, 3, 2, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).move_higher
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(1).move_to_bottom
|
||||
assert_equal [2, 3, 4, 1], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(1).move_to_top
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).move_to_bottom
|
||||
assert_equal [1, 3, 4, 2], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(4).move_to_top
|
||||
assert_equal [4, 1, 3, 2], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
end
|
||||
|
||||
def test_move_to_bottom_with_next_to_last_item
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
ListMixin.find(3).move_to_bottom
|
||||
assert_equal [1, 2, 4, 3], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
end
|
||||
|
||||
def test_next_prev
|
||||
assert_equal ListMixin.find(2), ListMixin.find(1).lower_item
|
||||
assert_nil ListMixin.find(1).higher_item
|
||||
assert_equal ListMixin.find(3), ListMixin.find(4).higher_item
|
||||
assert_nil ListMixin.find(4).lower_item
|
||||
end
|
||||
|
||||
def test_injection
|
||||
item = ListMixin.new(:parent_id => 1)
|
||||
assert_equal "parent_id = 1", item.scope_condition
|
||||
assert_equal "pos", item.position_column
|
||||
end
|
||||
|
||||
def test_insert
|
||||
new = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 1, new.pos
|
||||
assert new.first?
|
||||
assert new.last?
|
||||
|
||||
new = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 2, new.pos
|
||||
assert !new.first?
|
||||
assert new.last?
|
||||
|
||||
new = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 3, new.pos
|
||||
assert !new.first?
|
||||
assert new.last?
|
||||
|
||||
new = ListMixin.create(:parent_id => 0)
|
||||
assert_equal 1, new.pos
|
||||
assert new.first?
|
||||
assert new.last?
|
||||
end
|
||||
|
||||
def test_insert_at
|
||||
new = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 1, new.pos
|
||||
|
||||
new = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 2, new.pos
|
||||
|
||||
new = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 3, new.pos
|
||||
|
||||
new4 = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 4, new4.pos
|
||||
|
||||
new4.insert_at(3)
|
||||
assert_equal 3, new4.pos
|
||||
|
||||
new.reload
|
||||
assert_equal 4, new.pos
|
||||
|
||||
new.insert_at(2)
|
||||
assert_equal 2, new.pos
|
||||
|
||||
new4.reload
|
||||
assert_equal 4, new4.pos
|
||||
|
||||
new5 = ListMixin.create(:parent_id => 20)
|
||||
assert_equal 5, new5.pos
|
||||
|
||||
new5.insert_at(1)
|
||||
assert_equal 1, new5.pos
|
||||
|
||||
new4.reload
|
||||
assert_equal 5, new4.pos
|
||||
end
|
||||
|
||||
def test_delete_middle
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).destroy
|
||||
|
||||
assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
assert_equal 1, ListMixin.find(1).pos
|
||||
assert_equal 2, ListMixin.find(3).pos
|
||||
assert_equal 3, ListMixin.find(4).pos
|
||||
|
||||
ListMixin.find(1).destroy
|
||||
|
||||
assert_equal [3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&: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
|
||||
new2.move_higher
|
||||
assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos')
|
||||
end
|
||||
|
||||
|
||||
def test_remove_from_list_should_then_fail_in_list?
|
||||
assert_equal true, ListMixin.find(1).in_list?
|
||||
ListMixin.find(1).remove_from_list
|
||||
assert_equal false, ListMixin.find(1).in_list?
|
||||
end
|
||||
|
||||
def test_remove_from_list_should_set_position_to_nil
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).remove_from_list
|
||||
|
||||
assert_equal [2, 1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
assert_equal 1, ListMixin.find(1).pos
|
||||
assert_equal nil, ListMixin.find(2).pos
|
||||
assert_equal 2, ListMixin.find(3).pos
|
||||
assert_equal 3, ListMixin.find(4).pos
|
||||
end
|
||||
|
||||
def test_remove_before_destroy_does_not_shift_lower_items_twice
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).remove_from_list
|
||||
ListMixin.find(2).destroy
|
||||
|
||||
assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id)
|
||||
|
||||
assert_equal 1, ListMixin.find(1).pos
|
||||
assert_equal 2, ListMixin.find(3).pos
|
||||
assert_equal 3, ListMixin.find(4).pos
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ListSubTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
setup_db
|
||||
(1..4).each { |i| ((i % 2 == 1) ? ListMixinSub1 : ListMixinSub2).create! :pos => i, :parent_id => 5000 }
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_db
|
||||
end
|
||||
|
||||
def test_reordering
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).move_lower
|
||||
assert_equal [1, 3, 2, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).move_higher
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(1).move_to_bottom
|
||||
assert_equal [2, 3, 4, 1], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(1).move_to_top
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).move_to_bottom
|
||||
assert_equal [1, 3, 4, 2], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(4).move_to_top
|
||||
assert_equal [4, 1, 3, 2], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
end
|
||||
|
||||
def test_move_to_bottom_with_next_to_last_item
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
ListMixin.find(3).move_to_bottom
|
||||
assert_equal [1, 2, 4, 3], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
end
|
||||
|
||||
def test_next_prev
|
||||
assert_equal ListMixin.find(2), ListMixin.find(1).lower_item
|
||||
assert_nil ListMixin.find(1).higher_item
|
||||
assert_equal ListMixin.find(3), ListMixin.find(4).higher_item
|
||||
assert_nil ListMixin.find(4).lower_item
|
||||
end
|
||||
|
||||
def test_injection
|
||||
item = ListMixin.new("parent_id"=>1)
|
||||
assert_equal "parent_id = 1", item.scope_condition
|
||||
assert_equal "pos", item.position_column
|
||||
end
|
||||
|
||||
def test_insert_at
|
||||
new = ListMixin.create("parent_id" => 20)
|
||||
assert_equal 1, new.pos
|
||||
|
||||
new = ListMixinSub1.create("parent_id" => 20)
|
||||
assert_equal 2, new.pos
|
||||
|
||||
new = ListMixinSub2.create("parent_id" => 20)
|
||||
assert_equal 3, new.pos
|
||||
|
||||
new4 = ListMixin.create("parent_id" => 20)
|
||||
assert_equal 4, new4.pos
|
||||
|
||||
new4.insert_at(3)
|
||||
assert_equal 3, new4.pos
|
||||
|
||||
new.reload
|
||||
assert_equal 4, new.pos
|
||||
|
||||
new.insert_at(2)
|
||||
assert_equal 2, new.pos
|
||||
|
||||
new4.reload
|
||||
assert_equal 4, new4.pos
|
||||
|
||||
new5 = ListMixinSub1.create("parent_id" => 20)
|
||||
assert_equal 5, new5.pos
|
||||
|
||||
new5.insert_at(1)
|
||||
assert_equal 1, new5.pos
|
||||
|
||||
new4.reload
|
||||
assert_equal 5, new4.pos
|
||||
end
|
||||
|
||||
def test_delete_middle
|
||||
assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
ListMixin.find(2).destroy
|
||||
|
||||
assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
assert_equal 1, ListMixin.find(1).pos
|
||||
assert_equal 2, ListMixin.find(3).pos
|
||||
assert_equal 3, ListMixin.find(4).pos
|
||||
|
||||
ListMixin.find(1).destroy
|
||||
|
||||
assert_equal [3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos').map(&:id)
|
||||
|
||||
assert_equal 1, ListMixin.find(3).pos
|
||||
assert_equal 2, ListMixin.find(4).pos
|
||||
end
|
||||
|
||||
end
|
||||
35
vendor/plugins/memory_test_fix/README
vendored
35
vendor/plugins/memory_test_fix/README
vendored
|
|
@ -1,35 +0,0 @@
|
|||
MemoryTestFix
|
||||
=============
|
||||
|
||||
A simple fix to run tests with sqlite. From example at
|
||||
|
||||
http://blog.seagul.co.uk/articles/2006/02/08/in-memory-sqlite-database-for-rails-testing
|
||||
|
||||
In your database.yml, use
|
||||
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: ":memory:"
|
||||
|
||||
It runs much faster!
|
||||
|
||||
You can also adjust the verbosity of the output:
|
||||
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: ":memory:"
|
||||
verbosity: silent
|
||||
|
||||
== Authors
|
||||
|
||||
Chris Roos
|
||||
|
||||
Adapted by Geoffrey Grosenbach, http://nubyonrails.com
|
||||
|
||||
Verbosity patch by Kakutani Shintaro
|
||||
|
||||
== Changelog
|
||||
|
||||
* Updated to look for either so it works with Rails 1.2 and also older versions
|
||||
* Updated to use ActiveRecord::ConnectionAdapters::SQLite3Adapter for Rails 1.2
|
||||
|
||||
22
vendor/plugins/memory_test_fix/Rakefile
vendored
22
vendor/plugins/memory_test_fix/Rakefile
vendored
|
|
@ -1,22 +0,0 @@
|
|||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rake/rdoctask'
|
||||
|
||||
desc 'Default: run unit tests.'
|
||||
task :default => :test
|
||||
|
||||
desc 'Test the memory_test_fix plugin.'
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << 'lib'
|
||||
t.pattern = 'test/**/*_test.rb'
|
||||
t.verbose = true
|
||||
end
|
||||
|
||||
desc 'Generate documentation for the memory_test_fix plugin.'
|
||||
Rake::RDocTask.new(:rdoc) do |rdoc|
|
||||
rdoc.rdoc_dir = 'rdoc'
|
||||
rdoc.title = 'MemoryTestFix'
|
||||
rdoc.options << '--line-numbers' << '--inline-source'
|
||||
rdoc.rdoc_files.include('README')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
end
|
||||
7
vendor/plugins/memory_test_fix/about.yml
vendored
7
vendor/plugins/memory_test_fix/about.yml
vendored
|
|
@ -1,7 +0,0 @@
|
|||
author: Chris Roos
|
||||
summary: Makes SQLite3 memory tests possible by preloading the schema.
|
||||
homepage: http://blog.seagul.co.uk/articles/2006/02/08/in-memory-sqlite-database-for-rails-testing
|
||||
plugin: http://topfunky.net/svn/plugins/memory_test_fix
|
||||
license: MIT
|
||||
version: 0.1
|
||||
rails_version: 1.1+
|
||||
2
vendor/plugins/memory_test_fix/init.rb
vendored
2
vendor/plugins/memory_test_fix/init.rb
vendored
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
require 'memory_test_fix'
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
|
||||
# Update: Looks for the SQLite and SQLite3 adapters for
|
||||
# compatibility with Rails 1.2.2 and also older versions.
|
||||
def in_memory_database?
|
||||
if ENV["RAILS_ENV"] == "test" and
|
||||
(Rails::Configuration.new.database_configuration['test']['database'] == ':memory:' or
|
||||
Rails::Configuration.new.database_configuration['test']['dbfile'] == ':memory:')
|
||||
begin
|
||||
if ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
||||
return true
|
||||
end
|
||||
rescue NameError => e
|
||||
if ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLiteAdapter
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def verbosity
|
||||
Rails::Configuration.new.database_configuration['test']['verbosity']
|
||||
end
|
||||
|
||||
def inform_using_in_memory
|
||||
puts "Creating sqlite :memory: database"
|
||||
end
|
||||
|
||||
if in_memory_database?
|
||||
load_schema = lambda {
|
||||
#load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
|
||||
ActiveRecord::Migrator.up('db/migrate') # use migrations
|
||||
}
|
||||
case verbosity
|
||||
when "silent"
|
||||
silence_stream(STDOUT, &load_schema)
|
||||
when "quiet"
|
||||
inform_using_in_memory
|
||||
silence_stream(STDOUT, &load_schema)
|
||||
else
|
||||
inform_using_in_memory
|
||||
load_schema.call
|
||||
end
|
||||
end
|
||||
1
vendor/plugins/swf_fu/README.rdoc
vendored
1
vendor/plugins/swf_fu/README.rdoc
vendored
|
|
@ -48,6 +48,7 @@ You can specify alternate content either with the options <tt>:alt => "Get Flash
|
|||
* <tt>:mode</tt> - Either :dynamic (default) or :static. Refer to SWFObject's doc[http://code.google.com/p/swfobject/wiki/documentation#Should_I_use_the_static_or_dynamic_publishing_method?]
|
||||
* <tt>:flashvars</tt> - a Hash of variables that are passed to the swf. Can also be a string like <tt>"foo=bar&hello=world"</tt>. Defaults to <tt>{:id => the DOM id}</tt>
|
||||
* <tt>:parameters</tt> - a Hash of configuration parameters for the swf. See Adobe's doc[http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701#optional]
|
||||
* <tt>:html_options</tt> - a Hash of extra html options for the <tt>object</tt> tag.
|
||||
* <tt>:alt</tt> - HTML text that is displayed when the Flash player is not available. Defaults to a "Get Flash" image pointing to Adobe Flash's installation page. This can also be specified as a block (see embedding section). In Rails 3, this text is _assumed_ to be HTML, so there is no need to call +html_safe+ on it.
|
||||
* <tt>:flash_version</tt> - the version of the Flash player that is required (e.g. "7" (default) or "8.1.0")
|
||||
* <tt>:auto_install</tt> - a swf file that will upgrade flash player if needed (defaults to "expressInstall" which was installed by +swf_fu+)
|
||||
|
|
|
|||
8
vendor/plugins/swf_fu/init.rb
vendored
8
vendor/plugins/swf_fu/init.rb
vendored
|
|
@ -1,4 +1,4 @@
|
|||
require 'action_view/helpers/asset_tag_helper'
|
||||
ActionView::Helpers::AssetTagHelper rescue require 'action_view/helpers/asset_tag_helper' # Might be needed in some testing environments
|
||||
require File.dirname(__FILE__) + "/lib/action_view/helpers/swf_fu_helper"
|
||||
require File.dirname(__FILE__) + "/lib/action_view/helpers/asset_tag_helper/swf_asset"
|
||||
|
||||
|
|
@ -7,4 +7,8 @@ ActionView::Helpers.class_eval { include ActionView::Helpers::SwfFuHelper } # F
|
|||
ActionView::Base.class_eval { include ActionView::Helpers::SwfFuHelper } # ...and for older ones
|
||||
ActionView::TestCase.class_eval { include ActionView::Helpers::SwfFuHelper } if defined? ActionView::TestCase # ...for tests in older versions
|
||||
|
||||
ActionView::Helpers::AssetTagHelper.register_javascript_include_default 'swfobject'
|
||||
begin
|
||||
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :default => ["swfobject"]
|
||||
rescue NoMethodError # I think this might fail in Rails 2.1.x
|
||||
ActionView::Helpers::AssetTagHelper.register_javascript_include_default 'swfobject'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -68,7 +68,9 @@ module ActionView #:nodoc:
|
|||
end
|
||||
options.reverse_merge!(DEFAULTS)
|
||||
options[:id] ||= source.gsub(/^.*\//, '').gsub(/\.swf$/,'')
|
||||
options[:id] = force_to_valid_id(options[:id])
|
||||
options[:div_id] ||= options[:id]+"_div"
|
||||
options[:div_id] = force_to_valid_id(options[:div_id])
|
||||
options[:width], options[:height] = options[:size].scan(/^(\d*%?)x(\d*%?)$/).first if options[:size]
|
||||
options[:auto_install] &&= @view.swf_path(options[:auto_install])
|
||||
options[:flashvars][:id] ||= options[:id]
|
||||
|
|
@ -79,10 +81,18 @@ module ActionView #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
def force_to_valid_id(id)
|
||||
id = id.gsub /[^A-Za-z0-9\-_]/, "_" # HTML id can only contain these characters
|
||||
id = "swf_" + id unless id =~ /^[A-Z]/i # HTML id must start with alpha
|
||||
id
|
||||
end
|
||||
|
||||
def generate(&block)
|
||||
if block_given?
|
||||
@options[:alt] = @view.capture(&block)
|
||||
if Rails::VERSION::STRING < "2.2"
|
||||
if Rails::VERSION::STRING >= "3.0"
|
||||
send(@mode)
|
||||
elsif Rails::VERSION::STRING < "2.2"
|
||||
@view.concat(send(@mode), block.binding)
|
||||
else
|
||||
@view.concat(send(@mode))
|
||||
|
|
@ -184,4 +194,4 @@ module ActionView #:nodoc:
|
|||
end #class Generator
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
7
vendor/plugins/swf_fu/test/swf_fu_test.rb
vendored
7
vendor/plugins/swf_fu/test/swf_fu_test.rb
vendored
|
|
@ -118,6 +118,13 @@ class SwfFuTest < ActionView::TestCase
|
|||
|
||||
end
|
||||
|
||||
should "enforce HTML id validity" do
|
||||
div_result = '<div id="swf_123-456_ok___X_div">'
|
||||
assert_match /#{div_result}/, swf_tag("123-456_ok$!+X")
|
||||
obj_result = '"id":"swf_123-456_ok___X"'
|
||||
assert_match /#{obj_result}/, swf_tag("123-456_ok$!+X")
|
||||
end
|
||||
|
||||
should "treat initialize arrays as list of parameters" do
|
||||
assert_match 'initialize("hello","world")', swf_tag("mySwf", :initialize => ["hello", "world"], :javascript_class => "SomeClass")
|
||||
end
|
||||
|
|
|
|||
33
vendor/plugins/yaml_db/README
vendored
33
vendor/plugins/yaml_db/README
vendored
|
|
@ -1,33 +0,0 @@
|
|||
= YamlDb
|
||||
|
||||
YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.
|
||||
|
||||
This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.
|
||||
|
||||
Any database that has an ActiveRecord adapter should work.
|
||||
|
||||
== Usage
|
||||
|
||||
rake db:data:dump -> Dump contents of Rails database to db/data.yml
|
||||
rake db:data:load -> Load contents of db/data.yml into the database
|
||||
|
||||
Further, there are tasks db:dump and db:load which do the entire database (the equivalent of running db:schema:dump followed by db:data:load).
|
||||
|
||||
== Examples
|
||||
|
||||
One common use would be to switch your data from one database backend to another. For example, let's say you wanted to switch from SQLite to MySQL. You might execute the following steps:
|
||||
|
||||
1. rake db:dump
|
||||
|
||||
2. Edit config/database.yml and change your adapter to mysql, set up database params
|
||||
|
||||
3. mysqladmin create [database name]
|
||||
|
||||
4. rake db:load
|
||||
|
||||
== Credits
|
||||
|
||||
Created by Orion Henry and Adam Wiggins. Major updates by Ricardo Chimal, Jr. Patches contributed by Michael Irwin.
|
||||
|
||||
Send questions, feedback, or patches to the Heroku mailing list: http://groups.google.com/group/heroku
|
||||
|
||||
10
vendor/plugins/yaml_db/Rakefile
vendored
10
vendor/plugins/yaml_db/Rakefile
vendored
|
|
@ -1,10 +0,0 @@
|
|||
require 'rake'
|
||||
require 'spec/rake/spectask'
|
||||
|
||||
desc "Run all specs"
|
||||
Spec::Rake::SpecTask.new('spec') do |t|
|
||||
t.spec_files = FileList['spec/*_spec.rb']
|
||||
end
|
||||
|
||||
task :default => :spec
|
||||
|
||||
5
vendor/plugins/yaml_db/about.yml
vendored
5
vendor/plugins/yaml_db/about.yml
vendored
|
|
@ -1,5 +0,0 @@
|
|||
author: Orion Henry and Adam Wiggins of Heroku
|
||||
summary: Dumps and loads a database-independent data dump format in db/data.yml.
|
||||
homepage: http://opensource.heroku.com/
|
||||
license: MIT
|
||||
rails_version: 1.2+
|
||||
1
vendor/plugins/yaml_db/init.rb
vendored
1
vendor/plugins/yaml_db/init.rb
vendored
|
|
@ -1 +0,0 @@
|
|||
require 'yaml_db'
|
||||
170
vendor/plugins/yaml_db/lib/yaml_db.rb
vendored
170
vendor/plugins/yaml_db/lib/yaml_db.rb
vendored
|
|
@ -1,170 +0,0 @@
|
|||
require 'rubygems'
|
||||
require 'yaml'
|
||||
require 'active_record'
|
||||
|
||||
|
||||
module YamlDb
|
||||
def self.dump(filename)
|
||||
disable_logger
|
||||
YamlDb::Dump.dump(File.new(filename, "w"))
|
||||
reenable_logger
|
||||
end
|
||||
|
||||
def self.load(filename)
|
||||
disable_logger
|
||||
YamlDb::Load.load(File.new(filename, "r"))
|
||||
reenable_logger
|
||||
end
|
||||
|
||||
def self.disable_logger
|
||||
@@old_logger = ActiveRecord::Base.logger
|
||||
ActiveRecord::Base.logger = nil
|
||||
end
|
||||
|
||||
def self.reenable_logger
|
||||
ActiveRecord::Base.logger = @@old_logger
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module YamlDb::Utils
|
||||
def self.chunk_records(records)
|
||||
yaml = [ records ].to_yaml
|
||||
yaml.sub!("--- \n", "")
|
||||
yaml.sub!('- - -', ' - -')
|
||||
yaml
|
||||
end
|
||||
|
||||
def self.unhash(hash, keys)
|
||||
keys.map { |key| hash[key] }
|
||||
end
|
||||
|
||||
def self.unhash_records(records, keys)
|
||||
records.each_with_index do |record, index|
|
||||
records[index] = unhash(record, keys)
|
||||
end
|
||||
|
||||
records
|
||||
end
|
||||
|
||||
def self.convert_booleans(records, columns)
|
||||
records.each do |record|
|
||||
columns.each do |column|
|
||||
next if is_boolean(record[column])
|
||||
record[column] = (record[column] == 't' or record[column] == '1')
|
||||
end
|
||||
end
|
||||
records
|
||||
end
|
||||
|
||||
def self.boolean_columns(table)
|
||||
columns = ActiveRecord::Base.connection.columns(table).reject { |c| c.type != :boolean }
|
||||
columns.map { |c| c.name }
|
||||
end
|
||||
|
||||
def self.is_boolean(value)
|
||||
value.kind_of?(TrueClass) or value.kind_of?(FalseClass)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module YamlDb::Dump
|
||||
def self.dump(io)
|
||||
ActiveRecord::Base.connection.tables.each do |table|
|
||||
dump_table(io, table)
|
||||
end
|
||||
end
|
||||
|
||||
def self.dump_table(io, table)
|
||||
return if table_record_count(table).zero?
|
||||
|
||||
dump_table_columns(io, table)
|
||||
dump_table_records(io, table)
|
||||
end
|
||||
|
||||
def self.dump_table_columns(io, table)
|
||||
io.write("\n")
|
||||
io.write({ table => { 'columns' => table_column_names(table) } }.to_yaml)
|
||||
end
|
||||
|
||||
def self.dump_table_records(io, table)
|
||||
table_record_header(io)
|
||||
|
||||
column_names = table_column_names(table)
|
||||
|
||||
each_table_page(table) do |records|
|
||||
rows = YamlDb::Utils.unhash_records(records, column_names)
|
||||
io.write(YamlDb::Utils.chunk_records(records))
|
||||
end
|
||||
end
|
||||
|
||||
def self.table_record_header(io)
|
||||
io.write(" records: \n")
|
||||
end
|
||||
|
||||
def self.table_column_names(table)
|
||||
ActiveRecord::Base.connection.columns(table).map { |c| c.name }
|
||||
end
|
||||
|
||||
def self.each_table_page(table, records_per_page=1000)
|
||||
total_count = table_record_count(table)
|
||||
pages = (total_count.to_f / records_per_page).ceil - 1
|
||||
id = table_column_names(table).first
|
||||
boolean_columns = YamlDb::Utils.boolean_columns(table)
|
||||
|
||||
(0..pages).to_a.each do |page|
|
||||
sql_limit = "LIMIT #{records_per_page} OFFSET #{records_per_page*page}"
|
||||
records = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table} ORDER BY #{id} #{sql_limit}")
|
||||
records = YamlDb::Utils.convert_booleans(records, boolean_columns)
|
||||
yield records
|
||||
end
|
||||
end
|
||||
|
||||
def self.table_record_count(table)
|
||||
ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM #{table}").values.first.to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module YamlDb::Load
|
||||
def self.load(io)
|
||||
ActiveRecord::Base.connection.transaction do
|
||||
YAML.load_documents(io) do |ydoc|
|
||||
ydoc.keys.each do |table_name|
|
||||
next if ydoc[table_name].nil?
|
||||
load_table(table_name, ydoc[table_name])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.truncate_table(table)
|
||||
begin
|
||||
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
|
||||
rescue Exception
|
||||
ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_table(table, data)
|
||||
column_names = data['columns']
|
||||
truncate_table(table)
|
||||
load_records(table, column_names, data['records'])
|
||||
# Uncomment if using PostgreSQL
|
||||
# reset_pk_sequence!(table)
|
||||
end
|
||||
|
||||
def self.load_records(table, column_names, records)
|
||||
quoted_column_names = column_names.map { |column| ActiveRecord::Base.connection.quote_column_name(column) }.join(',')
|
||||
records.each do |record|
|
||||
ActiveRecord::Base.connection.execute("INSERT INTO #{table} (#{quoted_column_names}) VALUES (#{record.map { |r| ActiveRecord::Base.connection.quote(r) }.join(',')})")
|
||||
end
|
||||
end
|
||||
|
||||
# Uncomment if using PostgreSQL
|
||||
# def self.reset_pk_sequence!(table_name)
|
||||
# if ActiveRecord::Base.connection.kind_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
||||
# ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
7
vendor/plugins/yaml_db/spec/base.rb
vendored
7
vendor/plugins/yaml_db/spec/base.rb
vendored
|
|
@ -1,7 +0,0 @@
|
|||
require 'rubygems'
|
||||
require 'spec'
|
||||
|
||||
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
||||
require 'yaml_db'
|
||||
|
||||
|
||||
89
vendor/plugins/yaml_db/spec/yaml_dump_spec.rb
vendored
89
vendor/plugins/yaml_db/spec/yaml_dump_spec.rb
vendored
|
|
@ -1,89 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/base'
|
||||
|
||||
describe YamlDb::Dump do
|
||||
before do
|
||||
File.stub!(:new).with('dump.yml', 'w').and_return(StringIO.new)
|
||||
|
||||
ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
|
||||
ActiveRecord::Base.connection = mock('connection')
|
||||
ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable' ])
|
||||
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a'), mock('b', :name => 'b') ])
|
||||
ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
|
||||
ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@io = StringIO.new
|
||||
end
|
||||
|
||||
it "should return a formatted string" do
|
||||
YamlDb::Dump.table_record_header(@io)
|
||||
@io.rewind
|
||||
@io.read.should == " records: \n"
|
||||
end
|
||||
|
||||
it "should return a list of column names" do
|
||||
YamlDb::Dump.table_column_names('mytable').should == [ 'a', 'b' ]
|
||||
end
|
||||
|
||||
it "should return the total number of records in a table" do
|
||||
YamlDb::Dump.table_record_count('mytable').should == 2
|
||||
end
|
||||
|
||||
it "should return a yaml string that contains a table header and column names" do
|
||||
YamlDb::Dump.stub!(:table_column_names).with('mytable').and_return([ 'a', 'b' ])
|
||||
YamlDb::Dump.dump_table_columns(@io, 'mytable')
|
||||
@io.rewind
|
||||
@io.read.should == <<EOYAML
|
||||
|
||||
---
|
||||
mytable:
|
||||
columns:
|
||||
- a
|
||||
- b
|
||||
EOYAML
|
||||
end
|
||||
|
||||
it "should return all records from the database and return them when there is only 1 page" do
|
||||
YamlDb::Dump.each_table_page('mytable') do |records|
|
||||
records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
|
||||
end
|
||||
end
|
||||
|
||||
it "should paginate records from the database and return them" do
|
||||
ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 } ], [ { 'a' => 3, 'b' => 4 } ])
|
||||
|
||||
records = [ ]
|
||||
YamlDb::Dump.each_table_page('mytable', 1) do |page|
|
||||
page.size.should == 1
|
||||
records.concat(page)
|
||||
end
|
||||
|
||||
records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
|
||||
end
|
||||
|
||||
it "should return dump the records for a table in yaml to a given io stream" do
|
||||
YamlDb::Dump.dump_table_records(@io, 'mytable')
|
||||
@io.rewind
|
||||
@io.read.should == <<EOYAML
|
||||
records:
|
||||
- - 1
|
||||
- 2
|
||||
- - 3
|
||||
- 4
|
||||
EOYAML
|
||||
end
|
||||
|
||||
it "should dump a table's contents to yaml" do
|
||||
YamlDb::Dump.should_receive(:dump_table_columns)
|
||||
YamlDb::Dump.should_receive(:dump_table_records)
|
||||
YamlDb::Dump.dump_table(@io, 'mytable')
|
||||
end
|
||||
|
||||
it "should not dump a table's contents when the record count is zero" do
|
||||
YamlDb::Dump.stub!(:table_record_count).with('mytable').and_return(0)
|
||||
YamlDb::Dump.should_not_receive(:dump_table_columns)
|
||||
YamlDb::Dump.should_not_receive(:dump_table_records)
|
||||
YamlDb::Dump.dump_table(@io, 'mytable')
|
||||
end
|
||||
end
|
||||
88
vendor/plugins/yaml_db/spec/yaml_load_spec.rb
vendored
88
vendor/plugins/yaml_db/spec/yaml_load_spec.rb
vendored
|
|
@ -1,88 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/base'
|
||||
|
||||
describe YamlDb::Load do
|
||||
before do
|
||||
ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
|
||||
ActiveRecord::Base.connection = mock('connection')
|
||||
ActiveRecord::Base.connection.stub!(:transaction).and_yield
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@io = StringIO.new
|
||||
end
|
||||
|
||||
it "should truncate the table" do
|
||||
ActiveRecord::Base.connection.stub!(:execute).with("TRUNCATE mytable").and_return(true)
|
||||
ActiveRecord::Base.connection.should_not_receive(:execute).with("DELETE FROM mytable")
|
||||
YamlDb::Load.truncate_table('mytable')
|
||||
end
|
||||
|
||||
it "should delete the table if truncate throws an exception" do
|
||||
ActiveRecord::Base.connection.should_receive(:execute).with("TRUNCATE mytable").and_raise()
|
||||
ActiveRecord::Base.connection.should_receive(:execute).with("DELETE FROM mytable").and_return(true)
|
||||
YamlDb::Load.truncate_table('mytable')
|
||||
end
|
||||
|
||||
it "should insert records into a table" do
|
||||
ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
|
||||
ActiveRecord::Base.connection.stub!(:quote_column_name).with('b').and_return('b')
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(1).and_return("'1'")
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(2).and_return("'2'")
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(3).and_return("'3'")
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(4).and_return("'4'")
|
||||
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('1','2')")
|
||||
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('3','4')")
|
||||
|
||||
YamlDb::Load.load_records('mytable', ['a', 'b'], [[1, 2], [3, 4]])
|
||||
end
|
||||
|
||||
it "should quote column names that correspond to sql keywords" do
|
||||
ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
|
||||
ActiveRecord::Base.connection.stub!(:quote_column_name).with('count').and_return('"count"')
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(1).and_return("'1'")
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(2).and_return("'2'")
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(3).and_return("'3'")
|
||||
ActiveRecord::Base.connection.stub!(:quote).with(4).and_return("'4'")
|
||||
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('1','2')")
|
||||
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('3','4')")
|
||||
|
||||
YamlDb::Load.load_records('mytable', ['a', 'count'], [[1, 2], [3, 4]])
|
||||
end
|
||||
|
||||
it "should truncate the table and then load the records into the table" do
|
||||
YamlDb::Load.should_receive(:truncate_table).with('mytable')
|
||||
YamlDb::Load.should_receive(:load_records).with('mytable', ['a', 'b'], [[1, 2], [3, 4]])
|
||||
YamlDb::Load.should_receive(:reset_pk_sequence!).with('mytable')
|
||||
|
||||
YamlDb::Load.load_table('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] })
|
||||
end
|
||||
|
||||
it "should call load structure for each document in the file" do
|
||||
YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => {
|
||||
'columns' => [ 'a', 'b' ],
|
||||
'records' => [[1, 2], [3, 4]]
|
||||
} })
|
||||
YamlDb::Load.should_receive(:load_table).with('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] })
|
||||
YamlDb::Load.load(@io)
|
||||
end
|
||||
|
||||
it "should not call load structure when the document in the file contains no records" do
|
||||
YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => nil })
|
||||
YamlDb::Load.should_not_receive(:load_table)
|
||||
YamlDb::Load.load(@io)
|
||||
end
|
||||
|
||||
it "should call reset pk sequence if the connection adapter is postgres" do
|
||||
module ActiveRecord; module ConnectionAdapters; class PostgreSQLAdapter; end; end; end;
|
||||
ActiveRecord::Base.connection.stub!(:kind_of?).with(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).and_return(true)
|
||||
ActiveRecord::Base.connection.should_receive(:reset_pk_sequence!).with('mytable')
|
||||
YamlDb::Load.reset_pk_sequence!('mytable')
|
||||
end
|
||||
|
||||
it "should not call reset_pk_sequence if the connection adapter is not postgres" do
|
||||
module ActiveRecord; module ConnectionAdapters; class PostgreSQLAdapter; end; end; end;
|
||||
ActiveRecord::Base.connection.stub!(:kind_of?).with(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).and_return(false)
|
||||
ActiveRecord::Base.connection.should_not_receive(:reset_pk_sequence!)
|
||||
YamlDb::Load.reset_pk_sequence!('mytable')
|
||||
end
|
||||
end
|
||||
39
vendor/plugins/yaml_db/spec/yaml_utils_spec.rb
vendored
39
vendor/plugins/yaml_db/spec/yaml_utils_spec.rb
vendored
|
|
@ -1,39 +0,0 @@
|
|||
require File.dirname(__FILE__) + '/base'
|
||||
|
||||
describe YamlDb::Utils, " convert records utility method" do
|
||||
it "turns an array with one record into a yaml chunk" do
|
||||
YamlDb::Utils.chunk_records([ %w(a b) ]).should == <<EOYAML
|
||||
- - a
|
||||
- b
|
||||
EOYAML
|
||||
end
|
||||
|
||||
it "turns an array with two records into a yaml chunk" do
|
||||
YamlDb::Utils.chunk_records([ %w(a b), %w(x y) ]).should == <<EOYAML
|
||||
- - a
|
||||
- b
|
||||
- - x
|
||||
- y
|
||||
EOYAML
|
||||
end
|
||||
|
||||
it "returns an array of hash values using an array of ordered keys" do
|
||||
YamlDb::Utils.unhash({ 'a' => 1, 'b' => 2 }, [ 'b', 'a' ]).should == [ 2, 1 ]
|
||||
end
|
||||
|
||||
it "should unhash each hash an array using an array of ordered keys" do
|
||||
YamlDb::Utils.unhash_records([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ], [ 'b', 'a' ]).should == [ [ 2, 1 ], [ 4, 3 ] ]
|
||||
end
|
||||
|
||||
it "should return true if it is a boolean type" do
|
||||
YamlDb::Utils.is_boolean(true).should == true
|
||||
YamlDb::Utils.is_boolean('true').should_not == true
|
||||
end
|
||||
|
||||
it "should return an array of boolean columns" do
|
||||
ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
|
||||
ActiveRecord::Base.connection = mock('connection')
|
||||
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a',:type => :string), mock('b', :name => 'b',:type => :boolean) ])
|
||||
YamlDb::Utils.boolean_columns('mytable').should == ['b']
|
||||
end
|
||||
end
|
||||
23
vendor/plugins/yaml_db/tasks/yaml_db_tasks.rake
vendored
23
vendor/plugins/yaml_db/tasks/yaml_db_tasks.rake
vendored
|
|
@ -1,23 +0,0 @@
|
|||
namespace :db do
|
||||
desc "Dump schema and data to db/schema.rb and db/data.yml"
|
||||
task(:dump => [ "db:schema:dump", "db:data:dump" ])
|
||||
|
||||
desc "Load schema and data from db/schema.rb and db/data.yml"
|
||||
task(:load => [ "db:schema:load", "db:data:load" ])
|
||||
|
||||
namespace :data do
|
||||
def db_dump_data_file
|
||||
"#{RAILS_ROOT}/db/data.yml"
|
||||
end
|
||||
|
||||
desc "Dump contents of database to db/data.yml"
|
||||
task(:dump => :environment) do
|
||||
YamlDb.dump db_dump_data_file
|
||||
end
|
||||
|
||||
desc "Load contents of db/data.yml into database"
|
||||
task(:load => :environment) do
|
||||
YamlDb.load db_dump_data_file
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue