spree 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of spree might be problematic. Click here for more details.
- data/CHANGELOG +30 -0
- data/CONTRIBUTORS +38 -20
- data/app/controllers/admin/creditcard_payments_controller.rb +10 -3
- data/app/controllers/admin/orders_controller.rb +17 -16
- data/app/controllers/admin/products_controller.rb +12 -14
- data/app/controllers/admin/reports_controller.rb +12 -14
- data/app/controllers/admin/users_controller.rb +10 -5
- data/app/controllers/admin/zones_controller.rb +4 -1
- data/app/controllers/application.rb +0 -1
- data/app/controllers/checkout_controller.rb +96 -0
- data/app/controllers/content_controller.rb +11 -1
- data/app/controllers/orders_controller.rb +12 -33
- data/app/controllers/products_controller.rb +12 -7
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/controllers/states_controller.rb +14 -2
- data/app/controllers/taxons_controller.rb +6 -2
- data/app/controllers/users_controller.rb +9 -6
- data/app/helpers/application_helper.rb +1 -11
- data/app/helpers/products_helper.rb +3 -1
- data/app/helpers/spree/base_helper.rb +0 -26
- data/app/models/address.rb +3 -3
- data/app/models/app_configuration.rb +1 -0
- data/app/models/country.rb +4 -0
- data/app/models/creditcard.rb +6 -1
- data/app/models/creditcard_payment.rb +1 -1
- data/app/models/inventory_unit.rb +4 -1
- data/app/models/order.rb +37 -21
- data/app/models/product.rb +19 -8
- data/{vendor/extensions/shipping/app → app}/models/shipment.rb +20 -4
- data/{vendor/extensions/shipping/app → app}/models/shipping_category.rb +0 -0
- data/{vendor/extensions/shipping/app → app}/models/shipping_method.rb +6 -4
- data/app/models/state.rb +5 -0
- data/app/models/user.rb +4 -2
- data/app/models/variant.rb +19 -1
- data/app/presenters/checkout_presenter.rb +58 -0
- data/app/views/admin/creditcard_payments/edit.html.erb +1 -1
- data/app/views/admin/option_types/available.html.erb +1 -1
- data/app/views/admin/orders/index.html.erb +28 -18
- data/app/views/admin/orders/show.html.erb +1 -1
- data/app/views/admin/payments/index.html.erb +1 -1
- data/app/views/admin/products/_images.html.erb +1 -1
- data/app/views/admin/products/index.html.erb +17 -13
- data/app/views/admin/users/index.html.erb +8 -8
- data/app/views/admin/zones/index.html.erb +5 -2
- data/app/views/checkout/_form.html.erb +165 -0
- data/app/views/{creditcards → checkout}/cvv.html.erb +1 -1
- data/app/views/checkout/new.html.erb +6 -0
- data/app/views/layouts/admin.html.erb +2 -3
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/orders/_form.html.erb +6 -4
- data/app/views/orders/_google_order.html.erb +24 -0
- data/app/views/orders/_line_item.html.erb +2 -1
- data/app/views/orders/show.html.erb +4 -1
- data/app/views/products/index.html.erb +2 -1
- data/app/views/products/show.html.erb +4 -4
- data/app/views/shared/_footer.html.erb +12 -1
- data/app/views/shared/_login.html.erb +1 -1
- data/app/views/shared/_order_details.html.erb +8 -9
- data/app/views/shared/_products.html.erb +1 -1
- data/app/views/shared/_report_criteria.html.erb +28 -28
- data/app/views/states/index.js.erb +10 -1
- data/config/environment.rb +10 -4
- data/config/initializers/searchlogic.rb +6 -0
- data/config/locales/de.yml +14 -0
- data/config/locales/en-GB.yml +20 -6
- data/config/locales/en-US.yml +20 -4
- data/config/locales/es.yml +14 -0
- data/config/locales/fr-FR.yml +463 -0
- data/config/locales/fr-FR_rails.yml +115 -0
- data/config/locales/it.yml +14 -0
- data/config/locales/nb-NO.yml +457 -0
- data/config/locales/nb-NO_rails.yml +105 -0
- data/config/locales/pl.yml +14 -0
- data/config/locales/pt-BR.yml +14 -0
- data/config/locales/pt-PT.yml +14 -0
- data/config/locales/ru-RU.yml +458 -0
- data/config/locales/ru-RU_rails.yml +154 -0
- data/config/routes.rb +11 -4
- data/db/migrate/20090204200045_add_order_permalink.rb +13 -0
- data/db/migrate/20090225231119_add_more_needed_keys_items_and_conf.rb +19 -0
- data/db/migrate/20090302221152_give_all_users_user_role.rb +13 -0
- data/db/sample/orders.yml +1 -1
- data/lib/generators/instance/instance_generator.rb +1 -1
- data/lib/spree.rb +1 -1
- data/lib/spree/setup.rb +1 -1
- data/lib/tasks/database.rake +5 -2
- data/lib/tasks/release.rake +1 -1
- data/lib/tasks/upgrade.rake +11 -0
- data/public/assets/products/1009/mini/sean.jpg +0 -0
- data/public/assets/products/1009/original/sean.jpg +0 -0
- data/public/assets/products/1009/product/sean.jpg +0 -0
- data/public/assets/products/1009/small/sean.jpg +0 -0
- data/public/images/ajax_loader.gif +0 -0
- data/public/javascripts/checkout.js +284 -0
- data/public/javascripts/jquery-1.3.2.min.js +19 -0
- data/public/javascripts/jquery.validate.pack.js +15 -0
- data/public/stylesheets/checkout.css +25 -0
- data/public/stylesheets/spree-admin.css +6 -2
- data/public/stylesheets/spree.css +419 -432
- data/spec/controllers/countries_controller_spec.rb +3 -2
- data/spec/controllers/orders_controller_spec.rb +7 -5
- data/spec/controllers/states_controller_spec.rb +4 -2
- data/spec/models/creditcard_payment_spec.rb +6 -2
- data/spec/models/order_spec.rb +164 -157
- data/spec/models/product_spec.rb +2 -2
- data/vendor/extensions/payment_gateway/db/migrate/20090218091936_create_protx_gateway.rb +18 -0
- data/vendor/extensions/payment_gateway/lib/spree/payment_gateway.rb +7 -5
- data/vendor/extensions/shipping/app/controllers/admin/shipments_controller.rb +6 -5
- data/vendor/extensions/shipping/app/views/admin/shipments/index.html.erb +1 -1
- data/vendor/extensions/shipping/config/locales/nb-NO.yml +25 -0
- data/vendor/extensions/shipping/config/locales/ru-RU.yml +25 -0
- data/vendor/extensions/shipping/db/sample/shipping_methods.yml +5 -1
- data/vendor/extensions/shipping/db/sample/zone_members.yml +9 -1
- data/vendor/extensions/shipping/db/sample/zones.yml +4 -1
- data/vendor/extensions/shipping/lib/spree/shipping_calculator.rb +0 -16
- data/vendor/extensions/shipping/shipping_extension.rb +0 -15
- data/vendor/extensions/shipping/spec/models/shipping_method_spec.rb +16 -10
- data/vendor/extensions/shipping/spec/models/shipping_order_spec.rb +3 -17
- data/vendor/extensions/tax_calculator/config/locales/nb-NO.yml +30 -0
- data/vendor/extensions/tax_calculator/spec/models/{order_spec.rb → order_tax_calc_spec.rb} +2 -2
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/.specification +3 -5
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/LICENSE +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/README +9 -2
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/Rakefile +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/active_presenter.rb +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/active_presenter/base.rb +38 -8
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/active_presenter/version.rb +1 -1
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/tasks/doc.rake +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/lib/tasks/gem.rake +0 -0
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/test/base_test.rb +66 -30
- data/vendor/gems/{active_presenter-0.0.4 → active_presenter-0.0.6}/test/test_helper.rb +36 -0
- data/vendor/plugins/attribute_fu/lib/attribute_fu/associated_form_helper.rb +12 -4
- data/vendor/plugins/find_by_param/MIT-LICENSE +1 -1
- data/vendor/plugins/find_by_param/{README → README.markdown} +7 -1
- data/vendor/plugins/find_by_param/init.rb +0 -1
- data/vendor/plugins/find_by_param/lib/find_by_param.rb +23 -87
- data/vendor/plugins/find_by_param/test/find_by_param_test.rb +22 -8
- data/vendor/plugins/find_by_param/test/test_helper.rb +0 -1
- metadata +65 -193
- data/app/controllers/creditcards_controller.rb +0 -73
- data/app/models/order_filter.rb +0 -28
- data/app/models/user_filter.rb +0 -6
- data/app/views/creditcards/_form_credit_card.html.erb +0 -30
- data/app/views/creditcards/new.html.erb +0 -25
- data/app/views/shared/_paginate.html.erb +0 -34
- data/lib/plugins/paginating_find/CHANGELOG +0 -120
- data/lib/plugins/paginating_find/README +0 -89
- data/lib/plugins/paginating_find/init.rb +0 -2
- data/lib/plugins/paginating_find/lib/paginating_find.rb +0 -138
- data/lib/plugins/paginating_find/lib/paging_enumerator.rb +0 -158
- data/lib/plugins/paginating_find/lib/paging_helper.rb +0 -47
- data/lib/plugins/paginating_find/test_app/Rakefile +0 -10
- data/lib/plugins/paginating_find/test_app/app/controllers/application.rb +0 -2
- data/lib/plugins/paginating_find/test_app/config/boot.rb +0 -44
- data/lib/plugins/paginating_find/test_app/config/database.yml +0 -6
- data/lib/plugins/paginating_find/test_app/config/environment.rb +0 -53
- data/lib/plugins/paginating_find/test_app/config/environments/test.rb +0 -19
- data/lib/plugins/paginating_find/test_app/config/routes.rb +0 -22
- data/lib/plugins/paginating_find/test_app/script/breakpointer +0 -3
- data/lib/plugins/paginating_find/test_app/script/console +0 -3
- data/lib/plugins/paginating_find/test_app/test/fixtures/articles.yml +0 -19
- data/lib/plugins/paginating_find/test_app/test/fixtures/authors.yml +0 -7
- data/lib/plugins/paginating_find/test_app/test/fixtures/edits.yml +0 -11
- data/lib/plugins/paginating_find/test_app/test/fixtures/models.rb +0 -18
- data/lib/plugins/paginating_find/test_app/test/test_helper.rb +0 -33
- data/lib/plugins/paginating_find/test_app/test/unit/abstract_test.rb +0 -7
- data/lib/plugins/paginating_find/test_app/test/unit/group_test.rb +0 -40
- data/lib/plugins/paginating_find/test_app/test/unit/paginating_find_test.rb +0 -194
- data/lib/plugins/paginating_find/test_app/test/unit/paging_enumerator_test.rb +0 -143
- data/public/assets/products/1012/mini/bt.jpg +0 -0
- data/public/assets/products/1012/original/bt.jpg +0 -0
- data/public/assets/products/1012/product/bt.jpg +0 -0
- data/public/assets/products/1012/small/bt.jpg +0 -0
- data/spec/views/products/index.html.erb_spec.rb +0 -46
- data/spec/views/products/show.html.erb_spec.rb +0 -46
- data/vendor/extensions/shipping/app/controllers/shipments_controller.rb +0 -96
- data/vendor/extensions/shipping/app/helpers/shipments_helper.rb +0 -20
- data/vendor/extensions/shipping/app/views/orders/fatal_shipping.html.erb +0 -6
- data/vendor/extensions/shipping/app/views/shipments/_form.html.erb +0 -46
- data/vendor/extensions/shipping/app/views/shipments/edit.html.erb +0 -57
- data/vendor/extensions/shipping/app/views/shipments/new.html.erb +0 -10
@@ -1,7 +0,0 @@
|
|
1
|
-
|
2
|
-
$:.unshift(File.dirname(__FILE__) + '/../../../lib')
|
3
|
-
require 'paginating_find'
|
4
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
5
|
-
require File.join(File.dirname(__FILE__), '/../fixtures/models')
|
6
|
-
load(File.dirname(__FILE__) + "/../../db/schema.rb")
|
7
|
-
load(File.dirname(__FILE__) + "/../../../init.rb")
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_test.rb'
|
2
|
-
|
3
|
-
class GroupTest < Test::Unit::TestCase
|
4
|
-
def test_should_paginate_with_group
|
5
|
-
one = Article.create(:name => "one", :author_id => 1)
|
6
|
-
two = Article.create(:name => "two", :author_id => 1)
|
7
|
-
three = Article.create(:name => "three", :author_id => 1)
|
8
|
-
four = Article.create(:name => "four", :author_id => 2)
|
9
|
-
results = Article.find(:all, :group => "author_id", :page => {:size => 2})
|
10
|
-
assert_equal 2, results.size
|
11
|
-
assert results.to_a.include?(one)
|
12
|
-
assert !results.to_a.include?(two)
|
13
|
-
assert !results.to_a.include?(three)
|
14
|
-
assert results.to_a.include?(four)
|
15
|
-
assert_equal 1, results.page_count
|
16
|
-
assert_equal 2, results.page_size
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_should_paginate_with_group_and_order
|
20
|
-
one = Article.create(:name => "one", :author_id => 1)
|
21
|
-
two = Article.create(:name => "two", :author_id => 1)
|
22
|
-
three = Article.create(:name => "three", :author_id => 1)
|
23
|
-
four = Article.create(:name => "four", :author_id => 2)
|
24
|
-
results = Article.find(:all, :group => "author_id", :order => "name DESC", :page => {:size => 2})
|
25
|
-
assert_equal 2, results.size
|
26
|
-
assert_equal 1, results.page_count
|
27
|
-
assert_equal 2, results.page_size
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_should_work_with_having_tacked_onto_group
|
31
|
-
one = Article.create(:name => "one", :author_id => 1)
|
32
|
-
two = Article.create(:name => "two", :author_id => 1)
|
33
|
-
three = Article.create(:name => "three", :author_id => 1)
|
34
|
-
four = Article.create(:name => "four", :author_id => 2)
|
35
|
-
results = Article.find(:all, :group => "author_id HAVING author_id=1", :order => "name DESC", :page => {:size => 2})
|
36
|
-
assert_equal 1, results.size
|
37
|
-
assert_equal 1, results.page_count
|
38
|
-
assert_equal 2, results.page_size
|
39
|
-
end
|
40
|
-
end
|
@@ -1,194 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_test.rb'
|
2
|
-
|
3
|
-
class PaginatingFindTest < Test::Unit::TestCase
|
4
|
-
fixtures :authors, :edits, :articles
|
5
|
-
|
6
|
-
def test_should_not_bonk_on_marshal_dump
|
7
|
-
results = Article.find(:all, :page => {:size => 2})
|
8
|
-
Marshal.dump(results)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_preserve_enumerator_stats_on_marshal_load
|
12
|
-
results = Article.find(:all, :page => {:size => 2})
|
13
|
-
loaded = Marshal.load(Marshal.dump(results))
|
14
|
-
assert_equal 2, loaded.page_size
|
15
|
-
assert_equal Article.count, loaded.size
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_auto_paginate
|
19
|
-
h = ArticleHelper.new(112)
|
20
|
-
h.find_articles(:all, :page => {:size => 10, :auto => true}) do |results|
|
21
|
-
results.each {} # enumerate all 112 results
|
22
|
-
assert_equal results.page_count, results.stop_page
|
23
|
-
assert_equal results.page_count, results.page
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_paginate
|
28
|
-
h = ArticleHelper.new(112)
|
29
|
-
h.find_articles(:all, :page => {:size => 10}) do |results|
|
30
|
-
results.each {} # enumerate first 10 results
|
31
|
-
results.next_page! # move to next page
|
32
|
-
results.page = 2
|
33
|
-
results.each {} # enumerate next 10 results
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_should_not_paginate
|
38
|
-
results = Article.find(:all)
|
39
|
-
assert !results.respond_to?(:page_count)
|
40
|
-
assert !results.respond_to?(:page_size)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_paginate_with_conditions
|
44
|
-
h = ArticleHelper.new(20)
|
45
|
-
h.find_articles(:all, :conditions => "name = 1", :order => "name ASC", :page => {:size => 10}) do |results|
|
46
|
-
assert_equal 10, results.page_size
|
47
|
-
assert_equal 1, results.size
|
48
|
-
results.each {}
|
49
|
-
assert_equal 1, results.page
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_respect_limit
|
54
|
-
h = ArticleHelper.new(80, 52)
|
55
|
-
h.find_articles(:all, :limit => 52, :page => {:size => 10}) do |results|
|
56
|
-
assert_equal 52, results.size
|
57
|
-
assert_equal 10, results.page_size
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_not_query_for_count
|
62
|
-
h = ArticleHelper.new(80, 50)
|
63
|
-
h.find_articles(:all, :page => {:size => 10, :count => 50}) do |results|
|
64
|
-
assert_equal 50, results.size
|
65
|
-
assert_equal 10, results.page_size
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_should_use_limit_instead_of_count
|
70
|
-
h = ArticleHelper.new(80, 41)
|
71
|
-
h.find_articles(:all, :limit => 41, :page => {:size => 10, :count => 50}) do |results|
|
72
|
-
assert_equal 41, results.size
|
73
|
-
assert_equal 10, results.page_size
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_should_use_count_instead_of_limit
|
78
|
-
h = ArticleHelper.new(80, 41)
|
79
|
-
h.find_articles(:all, :limit => 50, :page => {:size => 10, :count => 41}) do |results|
|
80
|
-
assert_equal 41, results.size
|
81
|
-
assert_equal 10, results.page_size
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_respect_include
|
86
|
-
results = Article.find(:all,
|
87
|
-
:conditions => ["authors.id = ?", authors(:alex).id],
|
88
|
-
:include => [:author],
|
89
|
-
:page => {:size => 10})
|
90
|
-
assert_equal 1, results.size
|
91
|
-
assert_equal 10, results.page_size
|
92
|
-
assert_equal authors(:alex), results.to_a.first.author
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_should_correctly_count_through_associations
|
96
|
-
editors = articles(:testing).editors.find(:all,
|
97
|
-
:page => {:size => 20,
|
98
|
-
:first => 1,
|
99
|
-
:current => 1 })
|
100
|
-
assert_equal 20, editors.page_size
|
101
|
-
assert_equal articles(:testing).editors.count, editors.size
|
102
|
-
assert_equal articles(:testing).editors.count, editors.to_a.size
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_should_respect_scope
|
106
|
-
Article.find_with_scope({ :conditions => "name = 1" }) do
|
107
|
-
h = ArticleHelper.new(20)
|
108
|
-
h.find_articles(:all, :page => {:size => 10}) do |results|
|
109
|
-
assert_equal 1, results.size
|
110
|
-
assert_equal 1, results.to_a.size
|
111
|
-
assert_equal 10, results.page_size
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_should_respect_scope_with_include
|
117
|
-
h = ArticleHelper.new(20)
|
118
|
-
Article.find_with_scope({:conditions => "articles.name >= 1 and articles.name <= 3" }) do
|
119
|
-
h.find_articles(:all, :include => [:author, :edits], :page => {:size => 10, :current => 1, :first => 1}, :order => "articles.name ASC") do |results|
|
120
|
-
assert_equal 3, results.size
|
121
|
-
assert_equal 3, results.to_a.size
|
122
|
-
assert_equal 10, results.page_size
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_should_respect_nested_scope
|
128
|
-
h = ArticleHelper.new(20)
|
129
|
-
Article.find_with_scope({ :conditions => "name = 1" }) do
|
130
|
-
Article.find_with_scope({ :conditions => "name = 2" }) do
|
131
|
-
h.find_articles(:all, :page => {:size => 10}) do |results|
|
132
|
-
assert_equal 0, results.size
|
133
|
-
assert_equal 0, results.to_a.size
|
134
|
-
assert_equal 10, results.page_size
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# =)
|
141
|
-
def test_should_respect_out_of_scope_scope
|
142
|
-
results = nil
|
143
|
-
(1..20).each { |n| Article.create(:name => n, :author_id => 1) }
|
144
|
-
Article.find_with_scope({ :conditions => "name >= 1 and name <= 15" }) do
|
145
|
-
results = Article.find(:all, :page => {:size => 10, :auto => true})
|
146
|
-
end
|
147
|
-
assert_equal 10, results.page_size
|
148
|
-
assert_equal 15, results.size
|
149
|
-
assert_equal 15, results.to_a.size
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_should_respect_out_of_scope_scope_with_include
|
153
|
-
results = nil
|
154
|
-
(1..20).each { |n| Article.create(:name => n, :author_id => 1) }
|
155
|
-
Article.find_with_scope({ :conditions => "articles.name >= 1 and articles.name <= 15 and authors.id = 1", :include => [:author, :edits]}) do
|
156
|
-
results = Article.find(:all, :page => {:size => 10, :auto => true})
|
157
|
-
end
|
158
|
-
assert_equal 10, results.page_size
|
159
|
-
assert_equal 15, results.size
|
160
|
-
assert_equal 15, results.to_a.size
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
class ArticleHelper
|
166
|
-
def initialize(how_many, limit=nil)
|
167
|
-
@how_many = how_many
|
168
|
-
@limit=limit
|
169
|
-
end
|
170
|
-
|
171
|
-
# Create n number of articles, and query them using the specified
|
172
|
-
# arguments. Check that the correct number of pages were returned
|
173
|
-
# and yield the results.
|
174
|
-
#
|
175
|
-
def find_articles(*args)
|
176
|
-
(1..@how_many).each { |n| Article.create(:name => n, :author_id => 1) }
|
177
|
-
results = Article.find(*args)
|
178
|
-
if results.size > results.page_size
|
179
|
-
page_count, num_on_last_page = how_many.divmod(results.page_size)
|
180
|
-
page_count = page_count + 1 if num_on_last_page > 0
|
181
|
-
else
|
182
|
-
page_count = 1
|
183
|
-
end
|
184
|
-
if (page_count != results.page_count)
|
185
|
-
raise "Expected #{page_count} pages but there were #{results.page_count}"
|
186
|
-
end
|
187
|
-
yield results if block_given?
|
188
|
-
results
|
189
|
-
end
|
190
|
-
|
191
|
-
def how_many
|
192
|
-
@limit ? @limit : @how_many
|
193
|
-
end
|
194
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_test.rb'
|
2
|
-
require 'paging_enumerator'
|
3
|
-
|
4
|
-
class PagingEnumeratorTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_should_count_pages_correctly
|
7
|
-
assert_equal 4, enum(page_size, total_size).page_count
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_page
|
11
|
-
assert_equal(
|
12
|
-
(1..total_size).to_a,
|
13
|
-
iterate(enum(page_size, total_size, true)) # iterate enum
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_page_manually
|
18
|
-
assert_equal(
|
19
|
-
(1..page_size).to_a,
|
20
|
-
iterate(enum(page_size, total_size)) # iterate manual_paging enum
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_move_to_next_page
|
25
|
-
enum = enum(page_size, total_size)
|
26
|
-
|
27
|
-
# Iterate the enumeration and inspect the results
|
28
|
-
# and manually move to the next page
|
29
|
-
iterate(enum)
|
30
|
-
enum.next_page!
|
31
|
-
|
32
|
-
# Iterate the next page and verify that the enum
|
33
|
-
# returned the results from the next page
|
34
|
-
assert_equal(
|
35
|
-
((page_size + 1)..(page_size * 2)).to_a,
|
36
|
-
iterate(enum)
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_not_move_to_next_page
|
41
|
-
enum = enum(page_size, total_size)
|
42
|
-
|
43
|
-
# Iterate the enumeration and inspect the results
|
44
|
-
assert_equal (1..page_size).to_a, iterate(enum)
|
45
|
-
|
46
|
-
# Verify that we are able to iterate the same page twice in a row
|
47
|
-
assert_equal (1..page_size).to_a, iterate(enum)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_should_move_to_last_page
|
51
|
-
enum = enum(page_size, total_size)
|
52
|
-
|
53
|
-
# Iterate the enumeration and inspect the results
|
54
|
-
# then manually move to the last page
|
55
|
-
iterate(enum)
|
56
|
-
enum.last_page!
|
57
|
-
|
58
|
-
assert_equal([10], iterate(enum))
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_move
|
62
|
-
enum = enum(page_size, total_size)
|
63
|
-
assert_equal(1, enum.page)
|
64
|
-
enum.move!(2)
|
65
|
-
assert_equal(2, enum.page)
|
66
|
-
assert_equal(1, enum.first_page)
|
67
|
-
start_val = (page_size - 1) * 2
|
68
|
-
end_val = (page_size - 1) * 3
|
69
|
-
assert_equal (start_val..end_val).to_a, iterate(enum)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_move_should_respect_upper_boundary
|
73
|
-
enum = enum(page_size, total_size)
|
74
|
-
assert_equal(1, enum.page)
|
75
|
-
enum.move!(100) # try moving to really high page
|
76
|
-
assert_equal(enum.last_page, enum.page)
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_move_should_respect_lower_boundary
|
80
|
-
enum = enum(page_size, total_size)
|
81
|
-
assert_equal(1, enum.page)
|
82
|
-
enum.move!(-100) # try moving to low page
|
83
|
-
assert_equal(enum.first_page, enum.page)
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_should_raise_on_move
|
87
|
-
enum = enum(page_size, total_size, true)
|
88
|
-
assert_equal(1, enum.page)
|
89
|
-
assert_raises(ArgumentError) { enum.move!(2) }
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_next_page_should_respect_upper_boundar
|
93
|
-
enum = enum(page_size, total_size)
|
94
|
-
enum.last_page!
|
95
|
-
assert_equal enum.last_page, enum.page
|
96
|
-
enum.next_page!
|
97
|
-
assert_equal enum.last_page, enum.page
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_previous_page_should_respect_upper_boundar
|
101
|
-
enum = enum(page_size, total_size)
|
102
|
-
enum.first_page!
|
103
|
-
assert_equal enum.first_page, enum.page
|
104
|
-
enum.previous_page!
|
105
|
-
assert_equal enum.first_page, enum.page
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_should_handle_zero_page_size
|
109
|
-
enum(0, 1).each {}
|
110
|
-
end
|
111
|
-
|
112
|
-
def iterate(enum)
|
113
|
-
results = []
|
114
|
-
first_page = enum.first_page
|
115
|
-
enum.each do |e|
|
116
|
-
# Verify that the enum.first_page does not change as we iterate
|
117
|
-
assert_equal(first_page, enum.first_page)
|
118
|
-
# Verify that the enum.page is correct for the current enum value
|
119
|
-
assert_equal(((e - 1) / enum.page_size) + 1, enum.page)
|
120
|
-
results << e
|
121
|
-
end
|
122
|
-
results
|
123
|
-
end
|
124
|
-
|
125
|
-
# Build the PagingEnumerable with a certain page size and
|
126
|
-
# total number of elements. Set up a callback that pages
|
127
|
-
# integers in range 1..total_size.
|
128
|
-
def enum(page_size, total_size, auto = nil)
|
129
|
-
PagingEnumerator.new(page_size, total_size, auto) do |page|
|
130
|
-
lower = page == 1 ? 0 : (page - 1) * page_size
|
131
|
-
upper = lower + page_size - 1
|
132
|
-
(1..total_size).to_a[lower..upper]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def page_size
|
137
|
-
3
|
138
|
-
end
|
139
|
-
|
140
|
-
def total_size
|
141
|
-
10
|
142
|
-
end
|
143
|
-
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe '/products/index' do
|
4
|
-
before(:each) do
|
5
|
-
@product = mock_model(Product)
|
6
|
-
template.stub!(:small_image)
|
7
|
-
template.stub!(:breadcrumbs).and_return("")
|
8
|
-
@product.stub!(:master_price)
|
9
|
-
@product.stub!(:name).and_return('Delicious Cows')
|
10
|
-
@product.stub!(:has_stock?).and_return(true)
|
11
|
-
assigns[:products] = [@product]
|
12
|
-
|
13
|
-
# TODO: put these pagination stubs into a helper?
|
14
|
-
assigns[:products].stub!(:page_count).and_return(1)
|
15
|
-
assigns[:products].stub!(:first_page).and_return(true)
|
16
|
-
assigns[:products].stub!(:previous_page?).and_return(false)
|
17
|
-
assigns[:products].stub!(:next_page?).and_return(false)
|
18
|
-
template.stub!(:windowed_pagination_links).and_return(false)
|
19
|
-
template.stub_render(:partial => 'shared/taxonomies')
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should display items in stock" do
|
23
|
-
render '/products/index'
|
24
|
-
response.should have_tag('a[href=?]', product_path(@product), /#{@product.name}/)
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'with out-of-stock items' do
|
28
|
-
before(:each) do
|
29
|
-
@product.stub!(:has_stock?).and_return(false)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should not display if show_zero_stock_products is not set" do
|
33
|
-
Spree::Config.stub!(:[]).with(:show_zero_stock_products).and_return(false)
|
34
|
-
render '/products/index'
|
35
|
-
response.should_not have_tag('a[href=?]', product_path(@product), /#{@product.name}/)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should display if show_zero_stock_products is set" do
|
39
|
-
Spree::Config.stub!(:[]).with(:show_zero_stock_products).and_return(true)
|
40
|
-
render '/products/index'
|
41
|
-
response.should have_tag('a[href=?]', product_path(@product), /#{@product.name}/)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe '/product/show' do
|
5
|
-
before(:each) do
|
6
|
-
template.stub!(:product_image)
|
7
|
-
@product = Product.new(:name => 'Delicious Cows', :permalink => 'delicious-cows',
|
8
|
-
:description => 'Cows are delicious!', :master_price => 45.00,
|
9
|
-
:variants => [Variant.new]
|
10
|
-
)
|
11
|
-
@product.stub!(:images).and_return(mock(Image, :size => 1))
|
12
|
-
assigns[:product] = @product
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should display the item" do
|
16
|
-
render '/products/show'
|
17
|
-
response.should have_tag('td[class=?]', 'product-name', /#{@product.name}/)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'with out-of-stock items' do
|
21
|
-
before(:each) do
|
22
|
-
@product.stub!(:has_stock?).and_return(false)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should not display product if allow_backorders is not set" do
|
26
|
-
Spree::Config.stub!(:[]).with(:allow_backorders).and_return(false)
|
27
|
-
render '/products/show'
|
28
|
-
response.should have_tag('strong', /Out of Stock/)
|
29
|
-
response.should_not have_tag('input[type=?]', 'submit')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should display product if allow_backorders is set" do
|
33
|
-
Spree::Config.stub!(:[]).with(:allow_backorders).and_return(true)
|
34
|
-
render '/products/show'
|
35
|
-
response.should_not have_tag('strong', /Out of Stock/)
|
36
|
-
response.should have_tag('input[type=?]', 'submit')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# NOTE: the behavior of variants is largely described thru the variant_options
|
41
|
-
# helper method in app/helpers/spree/base_helpers.rb. For that reason,
|
42
|
-
# the variant testing lives there
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
|