acts_as_ordinalized 0.1.5 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -32,7 +32,7 @@ This is a simple acts_as gem providing the active record models with ordinal num
32
32
  end
33
33
 
34
34
  sphinx_collection = OrdinalizedWithSphinx.search
35
- ordinalized_collection.first.ordinal_number
35
+ sphinx_collection.first.ordinal_number
36
36
  => 1
37
37
 
38
38
  === Note on Patches/Pull Requests
data/Rakefile CHANGED
@@ -10,8 +10,8 @@ begin
10
10
  gem.email = "mandaryyyn@gmail.com"
11
11
  gem.homepage = "http://github.com/mandaryn/acts_as_ordinalized"
12
12
  gem.authors = ["mandaryn"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ gem.add_dependency "will_paginate"
14
+ gem.add_dependency "rails", "~> 2.3.5"
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
17
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_ordinalized}
8
- s.version = "0.1.5"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mandaryn"]
12
- s.date = %q{2010-08-18}
12
+ s.date = %q{2010-08-19}
13
13
  s.description = %q{This is a simple acts_as gem providing the active record models with ordinal numbers. The ordinals numbering is per query, but should work nicely with will paginate showing correct ordinal numbers on paginated results.}
14
14
  s.email = %q{mandaryyyn@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -41,12 +41,15 @@ Gem::Specification.new do |s|
41
41
  s.specification_version = 3
42
42
 
43
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
44
+ s.add_runtime_dependency(%q<will_paginate>, [">= 0"])
45
+ s.add_runtime_dependency(%q<rails>, ["~> 2.3.5"])
45
46
  else
46
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
47
+ s.add_dependency(%q<will_paginate>, [">= 0"])
48
+ s.add_dependency(%q<rails>, ["~> 2.3.5"])
47
49
  end
48
50
  else
49
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_dependency(%q<will_paginate>, [">= 0"])
52
+ s.add_dependency(%q<rails>, ["~> 2.3.5"])
50
53
  end
51
54
  end
52
55
 
@@ -16,13 +16,11 @@ module ActsAsOrdinalized
16
16
 
17
17
  #wrap various find methods with adding ordinal numbers to all returned models
18
18
  wrapped_methods.each do |method_name|
19
- if self.respond_to?(method_name)
20
- class_eval <<-EOV
21
- def self.#{method_name}(*args)
22
- ActsAsOrdinalized.ordinalize(super(*args))
23
- end
24
- EOV
25
- end
19
+ class_eval <<-EOV
20
+ def self.#{method_name}(*args)
21
+ ActsAsOrdinalized.ordinalize(super(*args))
22
+ end
23
+ EOV
26
24
  end
27
25
  end
28
26
  end
@@ -46,4 +44,6 @@ module ActsAsOrdinalized
46
44
  end
47
45
  end
48
46
 
49
- ActiveRecord::Base.class_eval { include ActsAsOrdinalized }
47
+ ActiveRecord::Base.class_eval { include ActsAsOrdinalized }
48
+ ActiveRecord::Associations::AssociationCollection.class_eval { undef_method(:paginate) }
49
+ ActiveRecord::Associations::AssociationCollection.class_eval { alias_method :method_missing, :method_missing_without_paginate }
@@ -3,6 +3,8 @@ require 'test/unit'
3
3
  require 'rubygems'
4
4
  gem 'activerecord'
5
5
  require 'active_record'
6
+ require 'will_paginate'
7
+ WillPaginate.enable_activerecord
6
8
 
7
9
  require "#{File.dirname(__FILE__)}/../lib/acts_as_ordinalized"
8
10
 
@@ -14,6 +16,12 @@ def setup_db
14
16
  t.column :test_order, :integer
15
17
  t.column :switch, :boolean
16
18
  end
19
+
20
+ create_table :more_ordinals do |t|
21
+ t.column :test_order, :integer
22
+ t.column :switch, :boolean
23
+ t.column :ordinal_id, :integer
24
+ end
17
25
  end
18
26
  end
19
27
 
@@ -25,6 +33,7 @@ end
25
33
 
26
34
  class Ordinal < ActiveRecord::Base
27
35
  acts_as_ordinalized
36
+ has_many :more_ordinals
28
37
  end
29
38
 
30
39
  class OrdinalTest < Test::Unit::TestCase
@@ -54,14 +63,6 @@ class OrdinalTest < Test::Unit::TestCase
54
63
  assert_equal nil, empty
55
64
  end
56
65
  end
57
- begin
58
- require 'will_paginate'
59
- WillPaginate.enable_activerecord
60
-
61
- class OrdinalWithPagination < ActiveRecord::Base
62
- acts_as_ordinalized
63
- set_table_name "ordinals"
64
- end
65
66
 
66
67
  class OrdinalWithPaginationTest < Test::Unit::TestCase
67
68
 
@@ -75,12 +76,38 @@ class OrdinalWithPaginationTest < Test::Unit::TestCase
75
76
  end
76
77
 
77
78
  def test_ordinal_with_pagination
78
- ordinals = OrdinalWithPagination.paginate(:page => 1, :per_page => 5, :order => "test_order ASC")
79
+ ordinals = Ordinal.paginate(:page => 1, :per_page => 5, :order => "test_order ASC")
79
80
  assert_equal [[1,1], [2,2], [3,3], [4,4], [5,5]], ordinals.map{|o| [o.test_order, o.ordinal_number] }
80
- ordinals2 = OrdinalWithPagination.paginate(:page => 2, :per_page => 5, :order => "test_order ASC")
81
+ ordinals2 = Ordinal.paginate(:page => 2, :per_page => 5, :order => "test_order ASC")
82
+ assert_equal [[6,6], [7,7], [8,8], [9,9], [10,10]], ordinals2.map{|o| [o.test_order, o.ordinal_number] }
83
+ end
84
+
85
+ end
86
+
87
+ class MoreOrdinal < ActiveRecord::Base
88
+ acts_as_ordinalized
89
+
90
+ named_scope :ordered, :order => "test_order ASC"
91
+ end
92
+
93
+ class OrdinalAssociationWithPaginationTest < Test::Unit::TestCase
94
+
95
+ def setup
96
+ setup_db
97
+ ordinal = Ordinal.create!(:test_order => 0)
98
+ (1..10).each { |counter| ordinal.more_ordinals.create!(:test_order => "#{counter}", :switch => counter.even?) }
99
+ end
100
+
101
+ def teardown
102
+ teardown_db
103
+ end
104
+
105
+ def test_ordinal_associations_with_pagination
106
+ ordinal = Ordinal.first
107
+ ordinals2 = ordinal.more_ordinals.ordered.paginate(:page => 2, :per_page => 5)
81
108
  assert_equal [[6,6], [7,7], [8,8], [9,9], [10,10]], ordinals2.map{|o| [o.test_order, o.ordinal_number] }
109
+ ordinals = ordinal.more_ordinals.ordered.paginate(:page => 1, :per_page => 5)
110
+ assert_equal [[1,1], [2,2], [3,3], [4,4], [5,5]], ordinals.map{|o| [o.test_order, o.ordinal_number] }
82
111
  end
83
112
 
84
113
  end
85
- rescue
86
- end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
8
+ - 2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - mandaryn
@@ -15,25 +15,39 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-18 00:00:00 +02:00
18
+ date: 2010-08-19 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rspec
22
+ name: will_paginate
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 13
29
+ hash: 3
30
30
  segments:
31
- - 1
32
- - 2
33
- - 9
34
- version: 1.2.9
35
- type: :development
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
36
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rails
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 9
44
+ segments:
45
+ - 2
46
+ - 3
47
+ - 5
48
+ version: 2.3.5
49
+ type: :runtime
50
+ version_requirements: *id002
37
51
  description: This is a simple acts_as gem providing the active record models with ordinal numbers. The ordinals numbering is per query, but should work nicely with will paginate showing correct ordinal numbers on paginated results.
38
52
  email: mandaryyyn@gmail.com
39
53
  executables: []