liszt 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/.gitignore +7 -3
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +9 -2
  4. data/Gemfile.rails2 +8 -0
  5. data/Gemfile.rails2.lock +45 -0
  6. data/Rakefile +32 -1
  7. data/lib/liszt/{list.rb → redis_list.rb} +12 -7
  8. data/lib/liszt/version.rb +1 -1
  9. data/lib/liszt.rb +28 -8
  10. data/test/dummy_2.3/Rakefile +10 -0
  11. data/test/dummy_2.3/app/controllers/application_controller.rb +10 -0
  12. data/test/dummy_2.3/app/models/group.rb +2 -0
  13. data/test/dummy_2.3/app/models/person.rb +3 -0
  14. data/test/dummy_2.3/config/boot.rb +114 -0
  15. data/test/dummy_2.3/config/database.yml +22 -0
  16. data/test/dummy_2.3/config/environment.rb +43 -0
  17. data/test/dummy_2.3/config/environments/development.rb +17 -0
  18. data/test/dummy_2.3/config/environments/test.rb +28 -0
  19. data/test/dummy_2.3/config/initializers/backtrace_silencers.rb +7 -0
  20. data/test/dummy_2.3/config/initializers/bundler.rb +4 -0
  21. data/test/dummy_2.3/config/initializers/cookie_verification_secret.rb +7 -0
  22. data/test/dummy_2.3/config/initializers/inflections.rb +10 -0
  23. data/test/{dummy → dummy_2.3}/config/initializers/mime_types.rb +0 -0
  24. data/test/dummy_2.3/config/initializers/new_rails_defaults.rb +21 -0
  25. data/test/dummy_2.3/config/initializers/session_store.rb +15 -0
  26. data/test/dummy_2.3/config/locales/en.yml +5 -0
  27. data/test/dummy_2.3/config/routes.rb +43 -0
  28. data/test/dummy_2.3/db/migrate/20110922194432_create_people.rb +15 -0
  29. data/test/dummy_2.3/db/migrate/20110922194512_create_groups.rb +12 -0
  30. data/test/dummy_2.3/db/schema.rb +27 -0
  31. data/test/dummy_2.3/db/seeds.rb +7 -0
  32. data/test/dummy_2.3/script/about +4 -0
  33. data/test/dummy_2.3/script/console +3 -0
  34. data/test/dummy_2.3/script/dbconsole +3 -0
  35. data/test/dummy_2.3/script/destroy +3 -0
  36. data/test/dummy_2.3/script/generate +3 -0
  37. data/test/dummy_2.3/script/performance/benchmarker +3 -0
  38. data/test/dummy_2.3/script/performance/profiler +3 -0
  39. data/test/dummy_2.3/script/plugin +3 -0
  40. data/test/dummy_2.3/script/runner +3 -0
  41. data/test/dummy_2.3/script/server +3 -0
  42. data/test/dummy_2.3/test/fixtures/groups.yml +12 -0
  43. data/test/dummy_2.3/test/fixtures/people.yml +59 -0
  44. data/test/{dummy → dummy_3.1}/Rakefile +0 -0
  45. data/test/{dummy → dummy_3.1}/app/controllers/application_controller.rb +0 -0
  46. data/test/{dummy/app/mailers → dummy_3.1/app/models}/.gitkeep +0 -0
  47. data/test/dummy_3.1/app/models/group.rb +2 -0
  48. data/test/dummy_3.1/app/models/person.rb +3 -0
  49. data/test/{dummy → dummy_3.1}/config/application.rb +3 -0
  50. data/test/{dummy → dummy_3.1}/config/boot.rb +0 -0
  51. data/test/{dummy → dummy_3.1}/config/database.yml +0 -0
  52. data/test/{dummy → dummy_3.1}/config/environment.rb +0 -0
  53. data/test/{dummy → dummy_3.1}/config/environments/development.rb +0 -0
  54. data/test/{dummy → dummy_3.1}/config/environments/test.rb +0 -0
  55. data/test/{dummy → dummy_3.1}/config/initializers/backtrace_silencers.rb +0 -0
  56. data/test/{dummy → dummy_3.1}/config/initializers/inflections.rb +0 -0
  57. data/test/dummy_3.1/config/initializers/mime_types.rb +5 -0
  58. data/test/{dummy → dummy_3.1}/config/initializers/secret_token.rb +0 -0
  59. data/test/{dummy → dummy_3.1}/config/initializers/session_store.rb +0 -0
  60. data/test/{dummy → dummy_3.1}/config/initializers/wrap_parameters.rb +0 -0
  61. data/test/{dummy → dummy_3.1}/config/locales/en.yml +0 -0
  62. data/test/{dummy → dummy_3.1}/config/routes.rb +0 -0
  63. data/test/{dummy → dummy_3.1}/config.ru +0 -0
  64. data/test/dummy_3.1/db/migrate/20110922194058_create_people.rb +11 -0
  65. data/test/dummy_3.1/db/migrate/20110922194126_create_groups.rb +8 -0
  66. data/test/dummy_3.1/db/schema.rb +29 -0
  67. data/test/{dummy/app/models → dummy_3.1/lib/assets}/.gitkeep +0 -0
  68. data/test/{dummy/lib/assets → dummy_3.1/log}/.gitkeep +0 -0
  69. data/test/{dummy → dummy_3.1}/script/rails +0 -0
  70. data/test/dummy_3.1/test/fixtures/groups.yml +12 -0
  71. data/test/dummy_3.1/test/fixtures/people.yml +59 -0
  72. data/test/liszt_test.rb +118 -2
  73. data/test/redis.conf +2 -0
  74. data/test/redis_list_test.rb +168 -0
  75. data/test/test_helper.rb +39 -2
  76. metadata +141 -73
  77. data/test/dummy/app/assets/javascripts/application.js +0 -7
  78. data/test/dummy/app/assets/stylesheets/application.css +0 -7
  79. data/test/dummy/app/helpers/application_helper.rb +0 -2
  80. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  81. data/test/dummy/config/environments/production.rb +0 -51
  82. data/test/dummy/log/.gitkeep +0 -0
  83. data/test/dummy/public/404.html +0 -26
  84. data/test/dummy/public/422.html +0 -26
  85. data/test/dummy/public/500.html +0 -26
  86. data/test/dummy/public/favicon.ico +0 -0
@@ -0,0 +1,43 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+
4
+ # Sample of regular route:
5
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
+ # Keep in mind you can assign values other than :controller and :action
7
+
8
+ # Sample of named route:
9
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
+ # This route can be invoked with purchase_url(:id => product.id)
11
+
12
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
13
+ # map.resources :products
14
+
15
+ # Sample resource route with options:
16
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
+
18
+ # Sample resource route with sub-resources:
19
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
+
21
+ # Sample resource route with more complex sub-resources
22
+ # map.resources :products do |products|
23
+ # products.resources :comments
24
+ # products.resources :sales, :collection => { :recent => :get }
25
+ # end
26
+
27
+ # Sample resource route within a namespace:
28
+ # map.namespace :admin do |admin|
29
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
+ # admin.resources :products
31
+ # end
32
+
33
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
+ # map.root :controller => "welcome"
35
+
36
+ # See how all your routes lay out with "rake routes"
37
+
38
+ # Install the default routes as the lowest priority.
39
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
+ # consider removing or commenting them out if you're using named routes and resources.
41
+ map.connect ':controller/:action/:id'
42
+ map.connect ':controller/:action/:id.:format'
43
+ end
@@ -0,0 +1,15 @@
1
+ class CreatePeople < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :people do |t|
4
+ t.string :name
5
+ t.integer :group_id
6
+ t.boolean :is_male
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :people
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ class CreateGroups < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :groups do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :groups
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of Active Record to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 20110922194512) do
13
+
14
+ create_table "groups", :force => true do |t|
15
+ t.datetime "created_at"
16
+ t.datetime "updated_at"
17
+ end
18
+
19
+ create_table "people", :force => true do |t|
20
+ t.string "name"
21
+ t.integer "group_id"
22
+ t.boolean "is_male"
23
+ t.datetime "created_at"
24
+ t.datetime "updated_at"
25
+ end
26
+
27
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Major.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,12 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one:
8
+ id: 1
9
+ two:
10
+ id: 2
11
+ three:
12
+ id: 3
@@ -0,0 +1,59 @@
1
+ nelson:
2
+ name: Nelson Renna
3
+ group_id: 1
4
+ is_male: true
5
+
6
+ tyrone:
7
+ name: Tyrone Higgin
8
+ group_id: 2
9
+ is_male: true
10
+
11
+ penelope:
12
+ name: Penelope Roser
13
+ group_id: 1
14
+ is_male: false
15
+
16
+ kelly:
17
+ name: Kelly Fouche
18
+ group_id: 2
19
+ is_male: false
20
+
21
+ julio:
22
+ name: Julio Wiltz
23
+ group_id: 1
24
+ is_male: true
25
+
26
+ javier:
27
+ name: Javier Perin
28
+ group_id: 2
29
+ is_male: true
30
+
31
+ jami:
32
+ name: Jami Deibert
33
+ group_id: 1
34
+ is_male: false
35
+
36
+ althea:
37
+ name: Althea Cost
38
+ group_id: 2
39
+ is_male: false
40
+
41
+ darryl:
42
+ name: Darryl Eadie
43
+ group_id: 1
44
+ is_male: true
45
+
46
+ marylou:
47
+ name: Marylou Kleve
48
+ group_id: 2
49
+ is_male: false
50
+
51
+ ted:
52
+ name: Ted Hohn
53
+ group_id: 1
54
+ is_male: true
55
+
56
+ guy:
57
+ name: Guy Marriner
58
+ group_id: 2
59
+ is_male: true
File without changes
@@ -0,0 +1,2 @@
1
+ class Group < ActiveRecord::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ class Person < ActiveRecord::Base
2
+ acts_as_liszt :scope => [:group_id, :is_male]
3
+ end
@@ -3,7 +3,9 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require
6
+ require "redis"
6
7
  require "liszt"
8
+ require "shoulda-context"
7
9
 
8
10
  module Dummy
9
11
  class Application < Rails::Application
@@ -40,3 +42,4 @@ module Dummy
40
42
  end
41
43
  end
42
44
 
45
+ Liszt.redis = Redis.new(:host => "localhost", :port => "10001")
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
File without changes
File without changes
File without changes
@@ -0,0 +1,11 @@
1
+ class CreatePeople < ActiveRecord::Migration
2
+ def change
3
+ create_table :people do |t|
4
+ t.string :name
5
+ t.integer :group_id
6
+ t.boolean :is_male
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class CreateGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :groups do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20110922194126) do
15
+
16
+ create_table "groups", :force => true do |t|
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ end
20
+
21
+ create_table "people", :force => true do |t|
22
+ t.string "name"
23
+ t.integer "group_id"
24
+ t.boolean "is_male"
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ end
28
+
29
+ end
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one:
8
+ id: 1
9
+ two:
10
+ id: 2
11
+ three:
12
+ id: 3
@@ -0,0 +1,59 @@
1
+ nelson:
2
+ name: Nelson Renna
3
+ group_id: 1
4
+ is_male: true
5
+
6
+ tyrone:
7
+ name: Tyrone Higgin
8
+ group_id: 2
9
+ is_male: true
10
+
11
+ penelope:
12
+ name: Penelope Roser
13
+ group_id: 1
14
+ is_male: false
15
+
16
+ kelly:
17
+ name: Kelly Fouche
18
+ group_id: 2
19
+ is_male: false
20
+
21
+ julio:
22
+ name: Julio Wiltz
23
+ group_id: 1
24
+ is_male: true
25
+
26
+ javier:
27
+ name: Javier Perin
28
+ group_id: 2
29
+ is_male: true
30
+
31
+ jami:
32
+ name: Jami Deibert
33
+ group_id: 1
34
+ is_male: false
35
+
36
+ althea:
37
+ name: Althea Cost
38
+ group_id: 2
39
+ is_male: false
40
+
41
+ darryl:
42
+ name: Darryl Eadie
43
+ group_id: 1
44
+ is_male: true
45
+
46
+ marylou:
47
+ name: Marylou Kleve
48
+ group_id: 2
49
+ is_male: false
50
+
51
+ ted:
52
+ name: Ted Hohn
53
+ group_id: 1
54
+ is_male: true
55
+
56
+ guy:
57
+ name: Guy Marriner
58
+ group_id: 2
59
+ is_male: true
data/test/liszt_test.rb CHANGED
@@ -1,7 +1,123 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class LisztTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Liszt
4
+ fixtures :groups
5
+ fixtures :people
6
+
7
+ setup do
8
+ Liszt.redis.flushall
9
+ end
10
+
11
+ context "before initialization" do
12
+ should "not be initialized" do
13
+ assert !people(:nelson).ordered_list_initialized?
14
+ end
15
+
16
+ should "initialize successfully" do
17
+ assert_nothing_raised { people(:nelson).initialize_list! }
18
+ assert people(:nelson).ordered_list_initialized?
19
+ end
20
+ end
21
+
22
+ context "after initialization" do
23
+ setup do
24
+ people(:nelson).initialize_list!(&:id)
25
+ @id = people(:nelson).id
26
+ @current_list = Person.ordered_list_ids(people(:nelson))
27
+ end
28
+
29
+ context "basic functionality" do
30
+ should "move to top" do
31
+ people(:nelson).move_to_top!
32
+ @current_list.delete(@id)
33
+ @current_list.unshift(@id)
34
+ assert_equal people(:nelson).ordered_list_ids, @current_list
35
+ end
36
+
37
+ should "move up" do
38
+ old_index = people(:nelson).ordered_list_ids.index(@id)
39
+ people(:nelson).move_up!
40
+ @current_list.swap(old_index, old_index - 1)
41
+ assert_equal people(:nelson).ordered_list_ids, @current_list
42
+ end
43
+
44
+ should "move down" do
45
+ old_index = people(:nelson).ordered_list_ids.index(@id)
46
+ people(:nelson).move_down!
47
+ @current_list.swap(old_index, old_index + 1)
48
+ assert_equal people(:nelson).ordered_list_ids, @current_list
49
+ end
50
+
51
+ should "move to bottom" do
52
+ people(:nelson).move_to_bottom!
53
+ @current_list.delete(@id)
54
+ @current_list.push(@id)
55
+ assert_equal people(:nelson).ordered_list_ids, @current_list
56
+ end
57
+ end
58
+
59
+ context "ActiveRecord hooks" do
60
+ setup do
61
+ Person.initialize_list!(:group_id => 1, :is_male => true)
62
+ @person = Person.new(:name => "John Smith", :group_id => 1, :is_male => true)
63
+ end
64
+
65
+ should "not be in list before saving" do
66
+ assert !@person.ordered_list_items.include?(@person)
67
+ end
68
+
69
+ should "be in list after saving" do
70
+ @person.save
71
+ assert @person.ordered_list_items.include?(@person)
72
+ end
73
+
74
+ should "be removed from list after deletion" do
75
+ @person.save
76
+ @person.destroy
77
+ assert !@person.ordered_list_items.include?(@person)
78
+ end
79
+ end
80
+
81
+ context "double_check" do
82
+ setup do
83
+ Person.initialize_list!(:group_id => 1, :is_male => true)
84
+ @person = Person.new(:name => "John Smith", :group_id => 1, :is_male => true)
85
+ end
86
+
87
+ should "not confirm the list when double_check=false" do
88
+ @person.save
89
+ @person.remove_from_list
90
+ assert !@person.ordered_list_items.include?(@person)
91
+ assert !@person.ordered_list_ids.include?(@person.id)
92
+ end
93
+
94
+ should "confirm the list when double_check=true" do
95
+ @person.save
96
+ @person.remove_from_list
97
+ assert @person.ordered_list_items(true).include?(@person)
98
+ assert @person.ordered_list_ids.include?(@person.id)
99
+ end
100
+ end
101
+ end
102
+
103
+ context "auto-initialization" do
104
+ setup do
105
+ Group.acts_as_liszt :sort_by => lambda { |o| o.id }
106
+ end
107
+
108
+ should "sort a newly initialized list with the given proc" do
109
+ assert !Group.ordered_list_initialized?
110
+ Group.initialize_list!
111
+ assert Group.ordered_list_initialized?
112
+ assert_equal Group.ordered_list_ids, [1, 2, 3]
113
+ end
114
+
115
+ should "sort a newly auto-initialized list with the given proc" do
116
+ g = Group.new
117
+ assert !Group.ordered_list_initialized?
118
+ g.save
119
+ assert Group.ordered_list_initialized?
120
+ assert_equal Group.ordered_list_ids, [1, 2, 3, g.id]
121
+ end
6
122
  end
7
123
  end
data/test/redis.conf ADDED
@@ -0,0 +1,2 @@
1
+ daemonize no
2
+ port 10001