spree 0.11.2 → 0.11.3
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/Rakefile +9 -8
- data/app/controllers/admin/base_controller.rb +31 -0
- data/app/controllers/admin/general_settings_controller.rb +9 -0
- data/app/controllers/admin/orders_controller.rb +8 -3
- data/app/controllers/admin/payments_controller.rb +8 -3
- data/app/controllers/admin/shipments_controller.rb +7 -2
- data/app/models/address.rb +42 -25
- data/app/models/app_configuration.rb +3 -0
- data/app/models/billing_integration.rb +1 -1
- data/app/models/line_item.rb +1 -1
- data/app/models/payment.rb +1 -1
- data/app/models/product_group.rb +8 -4
- data/app/models/spree/alert.rb +13 -0
- data/config/boot.rb +1 -1
- data/config/environment.rb +3 -3
- data/config/environments/test.rb +1 -1
- data/config/locales/en_spree.yml +3 -0
- data/config/routes.rb +2 -1
- data/lib/generators/extension/templates/Rakefile +1 -1
- data/lib/plugins/option_tags_with_disable/Rakefile +1 -1
- data/lib/spree.rb +2 -2
- data/lib/spree/checkout/action_options.rb +2 -2
- data/lib/spree/extension_loader.rb +1 -1
- data/lib/spree/initializer.rb +3 -2
- data/lib/validation_group.rb +2 -2
- data/vendor/extensions/api/Rakefile +1 -1
- data/vendor/extensions/overview_dashboard/Rakefile +1 -1
- data/vendor/extensions/payment_gateway/Rakefile +1 -1
- data/vendor/extensions/payment_gateway/app/models/gateway/authorize_net.rb +8 -2
- data/vendor/extensions/payment_gateway/app/models/gateway/authorize_net_cim.rb +6 -0
- data/vendor/extensions/theme_default/Rakefile +1 -1
- data/vendor/extensions/theme_default/app/views/admin/adjustments/_form.html.erb +0 -3
- data/vendor/extensions/theme_default/app/views/admin/adjustments/new.html.erb +3 -0
- data/vendor/extensions/theme_default/app/views/admin/general_settings/edit.html.erb +8 -0
- data/vendor/extensions/theme_default/app/views/admin/general_settings/show.html.erb +5 -0
- data/vendor/extensions/theme_default/app/views/admin/shared/_alert.html.erb +11 -0
- data/vendor/extensions/theme_default/app/views/layouts/admin.html.erb +1 -1
- data/vendor/extensions/theme_default/public/stylesheets/admin/admin.css +30 -1
- data/vendor/plugins/acts_as_tree/Rakefile +1 -1
- data/vendor/plugins/attribute_fu/Rakefile +1 -1
- data/vendor/plugins/auto_complete/Rakefile +1 -1
- data/vendor/plugins/awesome_nested_set/Rakefile +1 -1
- data/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb +3 -3
- data/vendor/plugins/delegate_belongs_to/Rakefile +1 -1
- data/vendor/plugins/enumerable_constants/Rakefile +1 -1
- data/vendor/plugins/find_by_param/Rakefile +1 -1
- data/vendor/plugins/in_place_editing/Rakefile +1 -1
- data/vendor/plugins/jrails_auto_complete/Rakefile +1 -1
- data/vendor/plugins/mail_queue/Rakefile +1 -1
- data/vendor/plugins/open_id_authentication/Rakefile +1 -1
- data/vendor/plugins/resource_controller/lib/resource_controller/action_options.rb +1 -1
- data/vendor/plugins/resource_controller/lib/resource_controller/failable_action_options.rb +1 -1
- data/vendor/plugins/resource_controller/test/app/controllers/accounts_controller.rb +6 -0
- data/vendor/plugins/resource_controller/test/app/controllers/application.rb +7 -0
- data/vendor/plugins/resource_controller/test/app/controllers/cms/options_controller.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/controllers/cms/personnel_controller.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/controllers/cms/photos_controller.rb +6 -0
- data/vendor/plugins/resource_controller/test/app/controllers/cms/products_controller.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/controllers/comments_controller.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/controllers/images_controller.rb +4 -0
- data/vendor/plugins/resource_controller/test/app/controllers/options_controller.rb +8 -0
- data/vendor/plugins/resource_controller/test/app/controllers/people_controller.rb +9 -0
- data/vendor/plugins/resource_controller/test/app/controllers/photos_controller.rb +11 -0
- data/vendor/plugins/resource_controller/test/app/controllers/posts_controller.rb +10 -0
- data/vendor/plugins/resource_controller/test/app/controllers/projects_controller.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/controllers/somethings_controller.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/controllers/tags_controller.rb +13 -0
- data/vendor/plugins/resource_controller/test/app/controllers/users_controller.rb +12 -0
- data/vendor/plugins/resource_controller/test/app/helpers/accounts_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/application_helper.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/helpers/cms/products_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/comments_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/images_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/options_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/people_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/photos_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/posts_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/projects_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/somethings_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/tags_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/helpers/users_helper.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/models/account.rb +4 -0
- data/vendor/plugins/resource_controller/test/app/models/comment.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/image.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/option.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/personnel.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/photo.rb +5 -0
- data/vendor/plugins/resource_controller/test/app/models/post.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/product.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/project.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/models/something.rb +2 -0
- data/vendor/plugins/resource_controller/test/app/models/tag.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/models/user.rb +3 -0
- data/vendor/plugins/resource_controller/test/app/views/accounts/_form.html.erb +4 -0
- data/vendor/plugins/resource_controller/test/app/views/accounts/edit.html.erb +14 -0
- data/vendor/plugins/resource_controller/test/app/views/accounts/new.html.erb +12 -0
- data/vendor/plugins/resource_controller/test/app/views/accounts/show.html.erb +5 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/options/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/options/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/options/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/options/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/photos/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/products/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/products/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/products/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/cms/products/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/comments/edit.rhtml +27 -0
- data/vendor/plugins/resource_controller/test/app/views/comments/index.rhtml +24 -0
- data/vendor/plugins/resource_controller/test/app/views/comments/new.rhtml +26 -0
- data/vendor/plugins/resource_controller/test/app/views/comments/show.rhtml +18 -0
- data/vendor/plugins/resource_controller/test/app/views/images/_form.html.erb +4 -0
- data/vendor/plugins/resource_controller/test/app/views/images/edit.html.erb +14 -0
- data/vendor/plugins/resource_controller/test/app/views/images/new.html.erb +12 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/application.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/comments.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/options.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/people.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/photos.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/projects.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/somethings.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/layouts/tags.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/options/_form.html.erb +8 -0
- data/vendor/plugins/resource_controller/test/app/views/options/edit.html.erb +16 -0
- data/vendor/plugins/resource_controller/test/app/views/options/index.html.erb +21 -0
- data/vendor/plugins/resource_controller/test/app/views/options/new.html.erb +12 -0
- data/vendor/plugins/resource_controller/test/app/views/options/show.html.erb +10 -0
- data/vendor/plugins/resource_controller/test/app/views/people/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/people/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/people/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/people/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/photos/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/photos/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/photos/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/photos/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/posts/edit.rhtml +22 -0
- data/vendor/plugins/resource_controller/test/app/views/posts/index.rhtml +22 -0
- data/vendor/plugins/resource_controller/test/app/views/posts/new.rhtml +21 -0
- data/vendor/plugins/resource_controller/test/app/views/posts/show.rhtml +13 -0
- data/vendor/plugins/resource_controller/test/app/views/projects/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/projects/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/projects/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/projects/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/somethings/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/somethings/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/somethings/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/somethings/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/tags/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/tags/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/tags/index.rjs +0 -0
- data/vendor/plugins/resource_controller/test/app/views/tags/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/tags/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/app/views/users/edit.rhtml +17 -0
- data/vendor/plugins/resource_controller/test/app/views/users/index.rhtml +20 -0
- data/vendor/plugins/resource_controller/test/app/views/users/new.rhtml +16 -0
- data/vendor/plugins/resource_controller/test/app/views/users/show.rhtml +8 -0
- data/vendor/plugins/resource_controller/test/config/boot.rb +109 -0
- data/vendor/plugins/resource_controller/test/config/database.yml +9 -0
- data/vendor/plugins/resource_controller/test/config/environment.rb +47 -0
- data/vendor/plugins/resource_controller/test/config/environments/development.rb +21 -0
- data/vendor/plugins/resource_controller/test/config/environments/test.rb +19 -0
- data/vendor/plugins/resource_controller/test/config/initializers/inflections.rb +14 -0
- data/vendor/plugins/resource_controller/test/config/routes.rb +61 -0
- data/vendor/plugins/resource_controller/test/db/migrate/001_create_posts.rb +12 -0
- data/vendor/plugins/resource_controller/test/db/migrate/002_create_products.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/003_create_comments.rb +13 -0
- data/vendor/plugins/resource_controller/test/db/migrate/004_create_options.rb +13 -0
- data/vendor/plugins/resource_controller/test/db/migrate/005_create_photos.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/006_create_tags.rb +17 -0
- data/vendor/plugins/resource_controller/test/db/migrate/007_create_somethings.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/008_create_accounts.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/009_add_account_id_to_photos.rb +9 -0
- data/vendor/plugins/resource_controller/test/db/migrate/010_create_projects.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/011_create_images.rb +12 -0
- data/vendor/plugins/resource_controller/test/db/migrate/012_create_users.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/013_create_personnel.rb +11 -0
- data/vendor/plugins/resource_controller/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
- data/vendor/plugins/resource_controller/test/db/schema.rb +78 -0
- data/vendor/plugins/resource_controller/test/script/console +3 -0
- data/vendor/plugins/resource_controller/test/script/destroy +3 -0
- data/vendor/plugins/resource_controller/test/script/generate +3 -0
- data/vendor/plugins/resource_controller/test/script/server +3 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/accounts.yml +7 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/comments.yml +11 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/images.yml +6 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/options.yml +9 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/personnel.yml +5 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/photos.yml +9 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/photos_tags.yml +3 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/posts.yml +9 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/products.yml +7 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/projects.yml +7 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/somethings.yml +7 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/tags.yml +7 -0
- data/vendor/plugins/resource_controller/test/test/fixtures/users.yml +5 -0
- data/vendor/plugins/resource_controller/test/test/functional/cms/options_controller_test.rb +23 -0
- data/vendor/plugins/resource_controller/test/test/functional/cms/photos_controller_test.rb +43 -0
- data/vendor/plugins/resource_controller/test/test/functional/cms/products_controller_test.rb +23 -0
- data/vendor/plugins/resource_controller/test/test/functional/comments_controller_test.rb +26 -0
- data/vendor/plugins/resource_controller/test/test/functional/images_controller_test.rb +37 -0
- data/vendor/plugins/resource_controller/test/test/functional/people_controller_test.rb +34 -0
- data/vendor/plugins/resource_controller/test/test/functional/photos_controller_test.rb +130 -0
- data/vendor/plugins/resource_controller/test/test/functional/posts_controller_test.rb +34 -0
- data/vendor/plugins/resource_controller/test/test/functional/projects_controller_test.rb +18 -0
- data/vendor/plugins/resource_controller/test/test/functional/somethings_controller_test.rb +28 -0
- data/vendor/plugins/resource_controller/test/test/functional/tags_controller_test.rb +64 -0
- data/vendor/plugins/resource_controller/test/test/functional/users_controller_test.rb +24 -0
- data/vendor/plugins/resource_controller/test/test/test_helper.rb +12 -0
- data/vendor/plugins/resource_controller/test/test/unit/accessors_test.rb +110 -0
- data/vendor/plugins/resource_controller/test/test/unit/account_test.rb +7 -0
- data/vendor/plugins/resource_controller/test/test/unit/action_options_test.rb +109 -0
- data/vendor/plugins/resource_controller/test/test/unit/base_test.rb +11 -0
- data/vendor/plugins/resource_controller/test/test/unit/comment_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/failable_action_options_test.rb +77 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/current_objects_test.rb +133 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/internal_test.rb +106 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/nested_test.rb +86 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/singleton_current_objects_test.rb +68 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/singleton_nested_test.rb +77 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/singleton_urls_test.rb +67 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers/urls_test.rb +75 -0
- data/vendor/plugins/resource_controller/test/test/unit/helpers_test.rb +25 -0
- data/vendor/plugins/resource_controller/test/test/unit/image_test.rb +7 -0
- data/vendor/plugins/resource_controller/test/test/unit/option_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/photo_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/post_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/project_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/response_collector_test.rb +49 -0
- data/vendor/plugins/resource_controller/test/test/unit/something_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/tag_test.rb +10 -0
- data/vendor/plugins/resource_controller/test/test/unit/urligence_test.rb +203 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/Rakefile +32 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/bin/convert_to_should_syntax +40 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/init.rb +3 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda.rb +43 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/active_record_helpers.rb +580 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/color.rb +77 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/controller_tests.rb +467 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/html.rb +201 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/xml.rb +170 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/gem/proc_extensions.rb +14 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/gem/shoulda.rb +239 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/general.rb +118 -0
- data/vendor/plugins/resource_controller/test/vendor/plugins/shoulda/lib/shoulda/private_helpers.rb +22 -0
- data/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb +2 -2
- data/vendor/plugins/unobtrusive_date_picker/Rakefile +1 -1
- metadata +270 -145
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test/unit/ui/console/testrunner'
|
2
|
+
|
3
|
+
# Completely stolen from redgreen gem
|
4
|
+
#
|
5
|
+
# Adds colored output to your tests. Specify <tt>color: true</tt> in
|
6
|
+
# your <tt>~/.shoulda.conf</tt> file to enable.
|
7
|
+
#
|
8
|
+
# *Bug*: for some reason, this adds another line of output to the end of
|
9
|
+
# every rake task, as though there was another (empty) set of tests.
|
10
|
+
# A fix would be most welcome.
|
11
|
+
#
|
12
|
+
module ThoughtBot::Shoulda::Color
|
13
|
+
COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } # :nodoc:
|
14
|
+
def self.method_missing(color_name, *args) # :nodoc:
|
15
|
+
color(color_name) + args.first + color(:clear)
|
16
|
+
end
|
17
|
+
def self.color(color) # :nodoc:
|
18
|
+
"\e[#{COLORS[color.to_sym]}m"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Test # :nodoc:
|
23
|
+
module Unit # :nodoc:
|
24
|
+
class TestResult # :nodoc:
|
25
|
+
alias :old_to_s :to_s
|
26
|
+
def to_s
|
27
|
+
if old_to_s =~ /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/
|
28
|
+
ThoughtBot::Shoulda::Color.send($1.to_i != 0 || $2.to_i != 0 ? :red : :green, $&)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class AutoRunner # :nodoc:
|
34
|
+
alias :old_initialize :initialize
|
35
|
+
def initialize(standalone)
|
36
|
+
old_initialize(standalone)
|
37
|
+
@runner = proc do |r|
|
38
|
+
Test::Unit::UI::Console::RedGreenTestRunner
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Failure # :nodoc:
|
44
|
+
alias :old_long_display :long_display
|
45
|
+
def long_display
|
46
|
+
# old_long_display.sub('Failure', ThoughtBot::Shoulda::Color.red('Failure'))
|
47
|
+
ThoughtBot::Shoulda::Color.red(old_long_display)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Error # :nodoc:
|
52
|
+
alias :old_long_display :long_display
|
53
|
+
def long_display
|
54
|
+
# old_long_display.sub('Error', ThoughtBot::Shoulda::Color.yellow('Error'))
|
55
|
+
ThoughtBot::Shoulda::Color.yellow(old_long_display)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module UI # :nodoc:
|
60
|
+
module Console # :nodoc:
|
61
|
+
class RedGreenTestRunner < Test::Unit::UI::Console::TestRunner # :nodoc:
|
62
|
+
def output_single(something, level=NORMAL)
|
63
|
+
return unless (output?(level))
|
64
|
+
something = case something
|
65
|
+
when '.' then ThoughtBot::Shoulda::Color.green('.')
|
66
|
+
when 'F' then ThoughtBot::Shoulda::Color.red("F")
|
67
|
+
when 'E' then ThoughtBot::Shoulda::Color.yellow("E")
|
68
|
+
else something
|
69
|
+
end
|
70
|
+
@io.write(something)
|
71
|
+
@io.flush
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,467 @@
|
|
1
|
+
module ThoughtBot # :nodoc:
|
2
|
+
module Shoulda # :nodoc:
|
3
|
+
module Controller
|
4
|
+
def self.included(other) # :nodoc:
|
5
|
+
other.class_eval do
|
6
|
+
extend ThoughtBot::Shoulda::Controller::ClassMethods
|
7
|
+
include ThoughtBot::Shoulda::Controller::InstanceMethods
|
8
|
+
ThoughtBot::Shoulda::Controller::ClassMethods::VALID_FORMATS.each do |format|
|
9
|
+
include "ThoughtBot::Shoulda::Controller::#{format.to_s.upcase}".constantize
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# = Macro test helpers for your controllers
|
15
|
+
#
|
16
|
+
# By using the macro helpers you can quickly and easily create concise and easy to read test suites.
|
17
|
+
#
|
18
|
+
# This code segment:
|
19
|
+
# context "on GET to :show for first record" do
|
20
|
+
# setup do
|
21
|
+
# get :show, :id => 1
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# should_assign_to :user
|
25
|
+
# should_respond_with :success
|
26
|
+
# should_render_template :show
|
27
|
+
# should_not_set_the_flash
|
28
|
+
#
|
29
|
+
# should "do something else really cool" do
|
30
|
+
# assert_equal 1, assigns(:user).id
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Would produce 5 tests for the +show+ action
|
35
|
+
#
|
36
|
+
# Furthermore, the should_be_restful helper will create an entire set of tests which will verify that your
|
37
|
+
# controller responds restfully to a variety of requested formats.
|
38
|
+
module ClassMethods
|
39
|
+
# Formats tested by #should_be_restful. Defaults to [:html, :xml]
|
40
|
+
VALID_FORMATS = Dir.glob(File.join(File.dirname(__FILE__), 'formats', '*.rb')).map { |f| File.basename(f, '.rb') }.map(&:to_sym) # :doc:
|
41
|
+
VALID_FORMATS.each {|f| require "shoulda/controller_tests/formats/#{f}.rb"}
|
42
|
+
|
43
|
+
# Actions tested by #should_be_restful
|
44
|
+
VALID_ACTIONS = [:index, :show, :new, :edit, :create, :update, :destroy] # :doc:
|
45
|
+
|
46
|
+
# A ResourceOptions object is passed into should_be_restful in order to configure the tests for your controller.
|
47
|
+
#
|
48
|
+
# Example:
|
49
|
+
# class UsersControllerTest < Test::Unit::TestCase
|
50
|
+
# load_all_fixtures
|
51
|
+
#
|
52
|
+
# def setup
|
53
|
+
# ...normal setup code...
|
54
|
+
# @user = User.find(:first)
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# should_be_restful do |resource|
|
58
|
+
# resource.identifier = :id
|
59
|
+
# resource.klass = User
|
60
|
+
# resource.object = :user
|
61
|
+
# resource.parent = []
|
62
|
+
# resource.actions = [:index, :show, :new, :edit, :update, :create, :destroy]
|
63
|
+
# resource.formats = [:html, :xml]
|
64
|
+
#
|
65
|
+
# resource.create.params = { :name => "bob", :email => 'bob@bob.com', :age => 13}
|
66
|
+
# resource.update.params = { :name => "sue" }
|
67
|
+
#
|
68
|
+
# resource.create.redirect = "user_url(@user)"
|
69
|
+
# resource.update.redirect = "user_url(@user)"
|
70
|
+
# resource.destroy.redirect = "users_url"
|
71
|
+
#
|
72
|
+
# resource.create.flash = /created/i
|
73
|
+
# resource.update.flash = /updated/i
|
74
|
+
# resource.destroy.flash = /removed/i
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# Whenever possible, the resource attributes will be set to sensible defaults.
|
79
|
+
#
|
80
|
+
class ResourceOptions
|
81
|
+
# Configuration options for the create, update, destroy actions under should_be_restful
|
82
|
+
class ActionOptions
|
83
|
+
# String evaled to get the target of the redirection.
|
84
|
+
# All of the instance variables set by the controller will be available to the
|
85
|
+
# evaled code.
|
86
|
+
#
|
87
|
+
# Example:
|
88
|
+
# resource.create.redirect = "user_url(@user.company, @user)"
|
89
|
+
#
|
90
|
+
# Defaults to a generated url based on the name of the controller, the action, and the resource.parents list.
|
91
|
+
attr_accessor :redirect
|
92
|
+
|
93
|
+
# String or Regexp describing a value expected in the flash. Will match against any flash key.
|
94
|
+
#
|
95
|
+
# Defaults:
|
96
|
+
# destroy:: /removed/
|
97
|
+
# create:: /created/
|
98
|
+
# update:: /updated/
|
99
|
+
attr_accessor :flash
|
100
|
+
|
101
|
+
# Hash describing the params that should be sent in with this action.
|
102
|
+
attr_accessor :params
|
103
|
+
end
|
104
|
+
|
105
|
+
# Configuration options for the denied actions under should_be_restful
|
106
|
+
#
|
107
|
+
# Example:
|
108
|
+
# context "The public" do
|
109
|
+
# setup do
|
110
|
+
# @request.session[:logged_in] = false
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# should_be_restful do |resource|
|
114
|
+
# resource.parent = :user
|
115
|
+
#
|
116
|
+
# resource.denied.actions = [:index, :show, :edit, :new, :create, :update, :destroy]
|
117
|
+
# resource.denied.flash = /get outta here/i
|
118
|
+
# resource.denied.redirect = 'new_session_url'
|
119
|
+
# end
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
class DeniedOptions
|
123
|
+
# String evaled to get the target of the redirection.
|
124
|
+
# All of the instance variables set by the controller will be available to the
|
125
|
+
# evaled code.
|
126
|
+
#
|
127
|
+
# Example:
|
128
|
+
# resource.create.redirect = "user_url(@user.company, @user)"
|
129
|
+
attr_accessor :redirect
|
130
|
+
|
131
|
+
# String or Regexp describing a value expected in the flash. Will match against any flash key.
|
132
|
+
#
|
133
|
+
# Example:
|
134
|
+
# resource.create.flash = /created/
|
135
|
+
attr_accessor :flash
|
136
|
+
|
137
|
+
# Actions that should be denied (only used by resource.denied). <i>Note that these actions will
|
138
|
+
# only be tested if they are also listed in +resource.actions+</i>
|
139
|
+
# The special value of :all will deny all of the REST actions.
|
140
|
+
attr_accessor :actions
|
141
|
+
end
|
142
|
+
|
143
|
+
# Name of key in params that references the primary key.
|
144
|
+
# Will almost always be :id (default), unless you are using a plugin or have patched rails.
|
145
|
+
attr_accessor :identifier
|
146
|
+
|
147
|
+
# Name of the ActiveRecord class this resource is responsible for. Automatically determined from
|
148
|
+
# test class if not explicitly set. UserTest => "User"
|
149
|
+
attr_accessor :klass
|
150
|
+
|
151
|
+
# Name of the instantiated ActiveRecord object that should be used by some of the tests.
|
152
|
+
# Defaults to the underscored name of the AR class. CompanyManager => :company_manager
|
153
|
+
attr_accessor :object
|
154
|
+
|
155
|
+
# Name of the parent AR objects. Can be set as parent= or parents=, and can take either
|
156
|
+
# the name of the parent resource (if there's only one), or an array of names (if there's
|
157
|
+
# more than one).
|
158
|
+
#
|
159
|
+
# Example:
|
160
|
+
# # in the routes...
|
161
|
+
# map.resources :companies do
|
162
|
+
# map.resources :people do
|
163
|
+
# map.resources :limbs
|
164
|
+
# end
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# # in the tests...
|
168
|
+
# class PeopleControllerTest < Test::Unit::TestCase
|
169
|
+
# should_be_restful do |resource|
|
170
|
+
# resource.parent = :companies
|
171
|
+
# end
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# class LimbsControllerTest < Test::Unit::TestCase
|
175
|
+
# should_be_restful do |resource|
|
176
|
+
# resource.parents = [:companies, :people]
|
177
|
+
# end
|
178
|
+
# end
|
179
|
+
attr_accessor :parent
|
180
|
+
alias parents parent
|
181
|
+
alias parents= parent=
|
182
|
+
|
183
|
+
# Actions that should be tested. Must be a subset of VALID_ACTIONS (default).
|
184
|
+
# Tests for each actionw will only be generated if the action is listed here.
|
185
|
+
# The special value of :all will test all of the REST actions.
|
186
|
+
#
|
187
|
+
# Example (for a read-only controller):
|
188
|
+
# resource.actions = [:show, :index]
|
189
|
+
attr_accessor :actions
|
190
|
+
|
191
|
+
# Formats that should be tested. Must be a subset of VALID_FORMATS (default).
|
192
|
+
# Each action will be tested against the formats listed here. The special value
|
193
|
+
# of :all will test all of the supported formats.
|
194
|
+
#
|
195
|
+
# Example:
|
196
|
+
# resource.actions = [:html, :xml]
|
197
|
+
attr_accessor :formats
|
198
|
+
|
199
|
+
# ActionOptions object specifying options for the create action.
|
200
|
+
attr_accessor :create
|
201
|
+
|
202
|
+
# ActionOptions object specifying options for the update action.
|
203
|
+
attr_accessor :update
|
204
|
+
|
205
|
+
# ActionOptions object specifying options for the desrtoy action.
|
206
|
+
attr_accessor :destroy
|
207
|
+
|
208
|
+
# DeniedOptions object specifying which actions should return deny a request, and what should happen in that case.
|
209
|
+
attr_accessor :denied
|
210
|
+
|
211
|
+
def initialize # :nodoc:
|
212
|
+
@create = ActionOptions.new
|
213
|
+
@update = ActionOptions.new
|
214
|
+
@destroy = ActionOptions.new
|
215
|
+
@denied = DeniedOptions.new
|
216
|
+
|
217
|
+
@create.flash ||= /created/i
|
218
|
+
@update.flash ||= /updated/i
|
219
|
+
@destroy.flash ||= /removed/i
|
220
|
+
@denied.flash ||= /denied/i
|
221
|
+
|
222
|
+
@create.params ||= {}
|
223
|
+
@update.params ||= {}
|
224
|
+
|
225
|
+
@actions = VALID_ACTIONS
|
226
|
+
@formats = VALID_FORMATS
|
227
|
+
@denied.actions = []
|
228
|
+
end
|
229
|
+
|
230
|
+
def normalize!(target) # :nodoc:
|
231
|
+
@denied.actions = VALID_ACTIONS if @denied.actions == :all
|
232
|
+
@actions = VALID_ACTIONS if @actions == :all
|
233
|
+
@formats = VALID_FORMATS if @formats == :all
|
234
|
+
|
235
|
+
@denied.actions = @denied.actions.map(&:to_sym)
|
236
|
+
@actions = @actions.map(&:to_sym)
|
237
|
+
@formats = @formats.map(&:to_sym)
|
238
|
+
|
239
|
+
ensure_valid_members(@actions, VALID_ACTIONS, 'actions')
|
240
|
+
ensure_valid_members(@denied.actions, VALID_ACTIONS, 'denied.actions')
|
241
|
+
ensure_valid_members(@formats, VALID_FORMATS, 'formats')
|
242
|
+
|
243
|
+
@identifier ||= :id
|
244
|
+
@klass ||= target.name.gsub(/ControllerTest$/, '').singularize.constantize
|
245
|
+
@object ||= @klass.name.tableize.singularize
|
246
|
+
@parent ||= []
|
247
|
+
@parent = [@parent] unless @parent.is_a? Array
|
248
|
+
|
249
|
+
collection_helper = [@parent, @object.to_s.pluralize, 'url'].flatten.join('_')
|
250
|
+
collection_args = @parent.map {|n| "@#{object}.#{n}"}.join(', ')
|
251
|
+
@destroy.redirect ||= "#{collection_helper}(#{collection_args})"
|
252
|
+
|
253
|
+
member_helper = [@parent, @object, 'url'].flatten.join('_')
|
254
|
+
member_args = [@parent.map {|n| "@#{object}.#{n}"}, "@#{object}"].flatten.join(', ')
|
255
|
+
@create.redirect ||= "#{member_helper}(#{member_args})"
|
256
|
+
@update.redirect ||= "#{member_helper}(#{member_args})"
|
257
|
+
@denied.redirect ||= "new_session_url"
|
258
|
+
end
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
def ensure_valid_members(ary, valid_members, name) # :nodoc:
|
263
|
+
invalid = ary - valid_members
|
264
|
+
raise ArgumentError, "Unsupported #{name}: #{invalid.inspect}" unless invalid.empty?
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# :section: should_be_restful
|
269
|
+
# Generates a full suite of tests for a restful controller.
|
270
|
+
#
|
271
|
+
# The following definition will generate tests for the +index+, +show+, +new+,
|
272
|
+
# +edit+, +create+, +update+ and +destroy+ actions, in both +html+ and +xml+ formats:
|
273
|
+
#
|
274
|
+
# should_be_restful do |resource|
|
275
|
+
# resource.parent = :user
|
276
|
+
#
|
277
|
+
# resource.create.params = { :title => "first post", :body => 'blah blah blah'}
|
278
|
+
# resource.update.params = { :title => "changed" }
|
279
|
+
# end
|
280
|
+
#
|
281
|
+
# This generates about 40 tests, all of the format:
|
282
|
+
# "on GET to :show should assign @user."
|
283
|
+
# "on GET to :show should not set the flash."
|
284
|
+
# "on GET to :show should render 'show' template."
|
285
|
+
# "on GET to :show should respond with success."
|
286
|
+
# "on GET to :show as xml should assign @user."
|
287
|
+
# "on GET to :show as xml should have ContentType set to 'application/xml'."
|
288
|
+
# "on GET to :show as xml should respond with success."
|
289
|
+
# "on GET to :show as xml should return <user/> as the root element."
|
290
|
+
# The +resource+ parameter passed into the block is a ResourceOptions object, and
|
291
|
+
# is used to configure the tests for the details of your resources.
|
292
|
+
#
|
293
|
+
def should_be_restful(&blk) # :yields: resource
|
294
|
+
resource = ResourceOptions.new
|
295
|
+
blk.call(resource)
|
296
|
+
resource.normalize!(self)
|
297
|
+
|
298
|
+
resource.formats.each do |format|
|
299
|
+
resource.actions.each do |action|
|
300
|
+
if self.respond_to? :"make_#{action}_#{format}_tests"
|
301
|
+
self.send(:"make_#{action}_#{format}_tests", resource)
|
302
|
+
else
|
303
|
+
should "test #{action} #{format}" do
|
304
|
+
flunk "Test for #{action} as #{format} not implemented"
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
# :section: Test macros
|
312
|
+
|
313
|
+
# Macro that creates a test asserting that the flash contains the given value.
|
314
|
+
# val can be a String, a Regex, or nil (indicating that the flash should not be set)
|
315
|
+
#
|
316
|
+
# Example:
|
317
|
+
#
|
318
|
+
# should_set_the_flash_to "Thank you for placing this order."
|
319
|
+
# should_set_the_flash_to /created/i
|
320
|
+
# should_set_the_flash_to nil
|
321
|
+
def should_set_the_flash_to(val)
|
322
|
+
if val
|
323
|
+
should "have #{val.inspect} in the flash" do
|
324
|
+
assert_contains flash.values, val, ", Flash: #{flash.inspect}"
|
325
|
+
end
|
326
|
+
else
|
327
|
+
should "not set the flash" do
|
328
|
+
assert_equal({}, flash, "Flash was set to:\n#{flash.inspect}")
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
# Macro that creates a test asserting that the flash is empty. Same as
|
334
|
+
# @should_set_the_flash_to nil@
|
335
|
+
def should_not_set_the_flash
|
336
|
+
should_set_the_flash_to nil
|
337
|
+
end
|
338
|
+
|
339
|
+
# Macro that creates a test asserting that the controller assigned to @name
|
340
|
+
#
|
341
|
+
# Example:
|
342
|
+
#
|
343
|
+
# should_assign_to :user
|
344
|
+
def should_assign_to(name)
|
345
|
+
should "assign @#{name}" do
|
346
|
+
assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
# Macro that creates a test asserting that the controller did not assign to @name
|
351
|
+
#
|
352
|
+
# Example:
|
353
|
+
#
|
354
|
+
# should_not_assign_to :user
|
355
|
+
def should_not_assign_to(name)
|
356
|
+
should "not assign to @#{name}" do
|
357
|
+
assert !assigns(name.to_sym), "@#{name} was visible"
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
# Macro that creates a test asserting that the controller responded with a 'response' status code.
|
362
|
+
# Example:
|
363
|
+
#
|
364
|
+
# should_respond_with :success
|
365
|
+
def should_respond_with(response)
|
366
|
+
should "respond with #{response}" do
|
367
|
+
assert_response response
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
# Macro that creates a test asserting that the controller rendered the given template.
|
372
|
+
# Example:
|
373
|
+
#
|
374
|
+
# should_render_template :new
|
375
|
+
def should_render_template(template)
|
376
|
+
should "render template #{template.inspect}" do
|
377
|
+
assert_template template.to_s
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
# Macro that creates a test asserting that the controller returned a redirect to the given path.
|
382
|
+
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
383
|
+
# set by the controller are available to the evaled string.
|
384
|
+
# Example:
|
385
|
+
#
|
386
|
+
# should_redirect_to '"/"'
|
387
|
+
# should_redirect_to "users_url(@user)"
|
388
|
+
def should_redirect_to(url)
|
389
|
+
should "redirect to #{url.inspect}" do
|
390
|
+
instantiate_variables_from_assigns do
|
391
|
+
assert_redirected_to eval(url, self.send(:binding), __FILE__, __LINE__)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
# Macro that creates a test asserting that the rendered view contains a <form> element.
|
397
|
+
def should_render_a_form
|
398
|
+
should "display a form" do
|
399
|
+
assert_select "form", true, "The template doesn't contain a <form> element"
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
module InstanceMethods # :nodoc:
|
405
|
+
|
406
|
+
private # :enddoc:
|
407
|
+
|
408
|
+
SPECIAL_INSTANCE_VARIABLES = %w{
|
409
|
+
_cookies
|
410
|
+
_flash
|
411
|
+
_headers
|
412
|
+
_params
|
413
|
+
_request
|
414
|
+
_response
|
415
|
+
_session
|
416
|
+
action_name
|
417
|
+
before_filter_chain_aborted
|
418
|
+
cookies
|
419
|
+
flash
|
420
|
+
headers
|
421
|
+
ignore_missing_templates
|
422
|
+
logger
|
423
|
+
params
|
424
|
+
request
|
425
|
+
request_origin
|
426
|
+
response
|
427
|
+
session
|
428
|
+
template
|
429
|
+
template_class
|
430
|
+
template_root
|
431
|
+
url
|
432
|
+
variables_added
|
433
|
+
}.map(&:to_s)
|
434
|
+
|
435
|
+
def instantiate_variables_from_assigns(*names, &blk)
|
436
|
+
old = {}
|
437
|
+
names = (@response.template.assigns.keys - SPECIAL_INSTANCE_VARIABLES) if names.empty?
|
438
|
+
names.each do |name|
|
439
|
+
old[name] = instance_variable_get("@#{name}")
|
440
|
+
instance_variable_set("@#{name}", assigns(name.to_sym))
|
441
|
+
end
|
442
|
+
blk.call
|
443
|
+
names.each do |name|
|
444
|
+
instance_variable_set("@#{name}", old[name])
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
def get_existing_record(res) # :nodoc:
|
449
|
+
(instance_variable_get("@#{res.object}")).tap do |record|
|
450
|
+
assert(record, "This test requires you to set @#{res.object} in your setup block")
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
def make_parent_params(resource, record = nil, parent_names = nil) # :nodoc:
|
455
|
+
parent_names ||= resource.parents.reverse
|
456
|
+
return {} if parent_names == [] # Base case
|
457
|
+
parent_name = parent_names.shift
|
458
|
+
parent = record ? record.send(parent_name) : parent_name.to_s.classify.constantize.find(:first)
|
459
|
+
|
460
|
+
{ :"#{parent_name}_id" => parent.to_param }.merge(make_parent_params(resource, parent, parent_names))
|
461
|
+
end
|
462
|
+
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|