liszt 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -3
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -2
- data/Gemfile.rails2 +8 -0
- data/Gemfile.rails2.lock +45 -0
- data/Rakefile +32 -1
- data/lib/liszt/{list.rb → redis_list.rb} +12 -7
- data/lib/liszt/version.rb +1 -1
- data/lib/liszt.rb +28 -8
- data/test/dummy_2.3/Rakefile +10 -0
- data/test/dummy_2.3/app/controllers/application_controller.rb +10 -0
- data/test/dummy_2.3/app/models/group.rb +2 -0
- data/test/dummy_2.3/app/models/person.rb +3 -0
- data/test/dummy_2.3/config/boot.rb +114 -0
- data/test/dummy_2.3/config/database.yml +22 -0
- data/test/dummy_2.3/config/environment.rb +43 -0
- data/test/dummy_2.3/config/environments/development.rb +17 -0
- data/test/dummy_2.3/config/environments/test.rb +28 -0
- data/test/dummy_2.3/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy_2.3/config/initializers/bundler.rb +4 -0
- data/test/dummy_2.3/config/initializers/cookie_verification_secret.rb +7 -0
- data/test/dummy_2.3/config/initializers/inflections.rb +10 -0
- data/test/{dummy → dummy_2.3}/config/initializers/mime_types.rb +0 -0
- data/test/dummy_2.3/config/initializers/new_rails_defaults.rb +21 -0
- data/test/dummy_2.3/config/initializers/session_store.rb +15 -0
- data/test/dummy_2.3/config/locales/en.yml +5 -0
- data/test/dummy_2.3/config/routes.rb +43 -0
- data/test/dummy_2.3/db/migrate/20110922194432_create_people.rb +15 -0
- data/test/dummy_2.3/db/migrate/20110922194512_create_groups.rb +12 -0
- data/test/dummy_2.3/db/schema.rb +27 -0
- data/test/dummy_2.3/db/seeds.rb +7 -0
- data/test/dummy_2.3/script/about +4 -0
- data/test/dummy_2.3/script/console +3 -0
- data/test/dummy_2.3/script/dbconsole +3 -0
- data/test/dummy_2.3/script/destroy +3 -0
- data/test/dummy_2.3/script/generate +3 -0
- data/test/dummy_2.3/script/performance/benchmarker +3 -0
- data/test/dummy_2.3/script/performance/profiler +3 -0
- data/test/dummy_2.3/script/plugin +3 -0
- data/test/dummy_2.3/script/runner +3 -0
- data/test/dummy_2.3/script/server +3 -0
- data/test/dummy_2.3/test/fixtures/groups.yml +12 -0
- data/test/dummy_2.3/test/fixtures/people.yml +59 -0
- data/test/{dummy → dummy_3.1}/Rakefile +0 -0
- data/test/{dummy → dummy_3.1}/app/controllers/application_controller.rb +0 -0
- data/test/{dummy/app/mailers → dummy_3.1/app/models}/.gitkeep +0 -0
- data/test/dummy_3.1/app/models/group.rb +2 -0
- data/test/dummy_3.1/app/models/person.rb +3 -0
- data/test/{dummy → dummy_3.1}/config/application.rb +3 -0
- data/test/{dummy → dummy_3.1}/config/boot.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/database.yml +0 -0
- data/test/{dummy → dummy_3.1}/config/environment.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/environments/development.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/environments/test.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/initializers/backtrace_silencers.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/initializers/inflections.rb +0 -0
- data/test/dummy_3.1/config/initializers/mime_types.rb +5 -0
- data/test/{dummy → dummy_3.1}/config/initializers/secret_token.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/initializers/session_store.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/initializers/wrap_parameters.rb +0 -0
- data/test/{dummy → dummy_3.1}/config/locales/en.yml +0 -0
- data/test/{dummy → dummy_3.1}/config/routes.rb +0 -0
- data/test/{dummy → dummy_3.1}/config.ru +0 -0
- data/test/dummy_3.1/db/migrate/20110922194058_create_people.rb +11 -0
- data/test/dummy_3.1/db/migrate/20110922194126_create_groups.rb +8 -0
- data/test/dummy_3.1/db/schema.rb +29 -0
- data/test/{dummy/app/models → dummy_3.1/lib/assets}/.gitkeep +0 -0
- data/test/{dummy/lib/assets → dummy_3.1/log}/.gitkeep +0 -0
- data/test/{dummy → dummy_3.1}/script/rails +0 -0
- data/test/dummy_3.1/test/fixtures/groups.yml +12 -0
- data/test/dummy_3.1/test/fixtures/people.yml +59 -0
- data/test/liszt_test.rb +118 -2
- data/test/redis.conf +2 -0
- data/test/redis_list_test.rb +168 -0
- data/test/test_helper.rb +39 -2
- metadata +141 -73
- data/test/dummy/app/assets/javascripts/application.js +0 -7
- data/test/dummy/app/assets/stylesheets/application.css +0 -7
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/environments/production.rb +0 -51
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- 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,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,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
|
File without changes
|
File without changes
|
@@ -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|
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
|
-
|
5
|
-
|
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