draper 0.17.0 → 1.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG.markdown +14 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +50 -31
  6. data/Readme.markdown +63 -92
  7. data/draper.gemspec +4 -2
  8. data/lib/draper/collection_decorator.rb +88 -0
  9. data/lib/draper/decoratable.rb +44 -0
  10. data/lib/draper/decorated_association.rb +55 -0
  11. data/lib/draper/decorator.rb +208 -0
  12. data/lib/draper/finders.rb +44 -0
  13. data/lib/draper/helper_proxy.rb +16 -0
  14. data/lib/draper/railtie.rb +17 -21
  15. data/lib/draper/security.rb +48 -0
  16. data/lib/draper/tasks/tu.rake +5 -0
  17. data/lib/draper/test/minitest_integration.rb +5 -24
  18. data/lib/draper/test/rspec_integration.rb +0 -6
  19. data/lib/draper/test/test_unit_integration.rb +9 -0
  20. data/lib/draper/version.rb +1 -1
  21. data/lib/draper/view_context.rb +24 -6
  22. data/lib/draper/view_helpers.rb +36 -0
  23. data/lib/draper.rb +42 -7
  24. data/lib/generators/decorator/decorator_generator.rb +1 -1
  25. data/lib/generators/decorator/templates/decorator.rb +0 -1
  26. data/lib/generators/rspec/decorator_generator.rb +1 -1
  27. data/lib/generators/test_unit/decorator_generator.rb +1 -1
  28. data/lib/generators/test_unit/templates/decorator_test.rb +0 -3
  29. data/spec/draper/collection_decorator_spec.rb +240 -0
  30. data/spec/draper/decoratable_spec.rb +164 -0
  31. data/spec/draper/decorated_association_spec.rb +130 -0
  32. data/spec/draper/decorator_spec.rb +497 -0
  33. data/spec/draper/finders_spec.rb +156 -0
  34. data/spec/draper/helper_proxy_spec.rb +12 -0
  35. data/spec/draper/security_spec.rb +158 -0
  36. data/spec/draper/view_helpers_spec.rb +41 -0
  37. data/spec/dummy/.rspec +2 -0
  38. data/spec/dummy/README.rdoc +261 -0
  39. data/spec/dummy/Rakefile +7 -0
  40. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  41. data/spec/dummy/app/controllers/localized_urls.rb +5 -0
  42. data/spec/dummy/app/controllers/posts_controller.rb +17 -0
  43. data/spec/dummy/app/decorators/post_decorator.rb +25 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/mailers/application_mailer.rb +3 -0
  46. data/spec/dummy/app/mailers/post_mailer.rb +9 -0
  47. data/spec/dummy/app/models/post.rb +3 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +11 -0
  49. data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +1 -0
  50. data/spec/dummy/app/views/posts/_post.html.erb +19 -0
  51. data/spec/dummy/app/views/posts/show.html.erb +1 -0
  52. data/spec/dummy/config/application.rb +64 -0
  53. data/spec/dummy/config/boot.rb +10 -0
  54. data/spec/dummy/config/database.yml +25 -0
  55. data/spec/dummy/config/environment.rb +5 -0
  56. data/spec/dummy/config/environments/development.rb +34 -0
  57. data/spec/dummy/config/environments/production.rb +55 -0
  58. data/spec/dummy/config/environments/test.rb +32 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/dummy/config/initializers/inflections.rb +15 -0
  61. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  62. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  63. data/spec/dummy/config/initializers/session_store.rb +8 -0
  64. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  65. data/spec/dummy/config/locales/en.yml +5 -0
  66. data/spec/dummy/config/routes.rb +7 -0
  67. data/spec/dummy/config.ru +4 -0
  68. data/spec/dummy/db/migrate/20121019115657_create_posts.rb +8 -0
  69. data/spec/dummy/db/schema.rb +21 -0
  70. data/spec/dummy/db/seeds.rb +2 -0
  71. data/spec/dummy/lib/tasks/spec.rake +5 -0
  72. data/spec/dummy/log/.gitkeep +0 -0
  73. data/spec/dummy/public/404.html +26 -0
  74. data/spec/dummy/public/422.html +26 -0
  75. data/spec/dummy/public/500.html +25 -0
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/dummy/script/rails +6 -0
  78. data/spec/dummy/spec/decorators/post_decorator_spec.rb +23 -0
  79. data/spec/dummy/spec/mailers/post_mailer_spec.rb +29 -0
  80. data/spec/dummy/spec/spec_helper.rb +9 -0
  81. data/spec/generators/decorator/decorator_generator_spec.rb +24 -5
  82. data/spec/integration/integration_spec.rb +33 -0
  83. data/spec/minitest-rails/spec_type_spec.rb +63 -0
  84. data/{performance → spec/performance}/decorators.rb +2 -4
  85. data/spec/spec_helper.rb +23 -26
  86. data/spec/support/action_controller.rb +12 -0
  87. data/spec/support/active_model.rb +7 -0
  88. data/spec/support/{samples/active_record.rb → active_record.rb} +5 -0
  89. data/spec/support/{samples → decorators}/decorator_with_application_helper.rb +1 -1
  90. data/spec/support/decorators/namespaced_product_decorator.rb +5 -0
  91. data/spec/support/decorators/non_active_model_product_decorator.rb +2 -0
  92. data/spec/support/decorators/product_decorator.rb +19 -0
  93. data/spec/support/decorators/products_decorator.rb +10 -0
  94. data/spec/support/decorators/some_thing_decorator.rb +2 -0
  95. data/spec/support/{samples → decorators}/specific_product_decorator.rb +0 -2
  96. data/spec/support/dummy_app.rb +84 -0
  97. data/spec/support/matchers/have_text.rb +50 -0
  98. data/spec/support/{samples → models}/namespaced_product.rb +1 -3
  99. data/spec/support/{samples → models}/non_active_model_product.rb +1 -0
  100. data/spec/support/{samples → models}/product.rb +13 -2
  101. data/spec/support/models/some_thing.rb +5 -0
  102. data/spec/support/models/uninferrable_decorator_model.rb +3 -0
  103. metadata +207 -98
  104. data/doc/ApplicationDecorator.html +0 -147
  105. data/doc/Draper/AllHelpers.html +0 -256
  106. data/doc/Draper/Base.html +0 -1222
  107. data/doc/Draper/DecoratorGenerator.html +0 -216
  108. data/doc/Draper/LazyHelpers.html +0 -174
  109. data/doc/Draper/ModelSupport.html +0 -164
  110. data/doc/Draper/System.html +0 -179
  111. data/doc/Draper.html +0 -123
  112. data/doc/_index.html +0 -172
  113. data/doc/class_list.html +0 -47
  114. data/doc/css/common.css +0 -1
  115. data/doc/css/full_list.css +0 -53
  116. data/doc/css/style.css +0 -320
  117. data/doc/file_list.html +0 -46
  118. data/doc/frames.html +0 -13
  119. data/doc/index.html +0 -172
  120. data/doc/js/app.js +0 -205
  121. data/doc/js/full_list.js +0 -150
  122. data/doc/js/jquery.js +0 -16
  123. data/doc/method_list.html +0 -174
  124. data/doc/top-level-namespace.html +0 -103
  125. data/lib/draper/active_model_support.rb +0 -27
  126. data/lib/draper/base.rb +0 -312
  127. data/lib/draper/decorated_enumerable_proxy.rb +0 -57
  128. data/lib/draper/model_support.rb +0 -17
  129. data/lib/draper/rspec_integration.rb +0 -2
  130. data/lib/draper/system.rb +0 -10
  131. data/lib/draper/test/view_context.rb +0 -12
  132. data/spec/draper/base_spec.rb +0 -863
  133. data/spec/draper/helper_support_spec.rb +0 -18
  134. data/spec/draper/model_support_spec.rb +0 -48
  135. data/spec/draper/view_context_spec.rb +0 -30
  136. data/spec/support/samples/active_model.rb +0 -9
  137. data/spec/support/samples/application_controller.rb +0 -42
  138. data/spec/support/samples/application_helper.rb +0 -8
  139. data/spec/support/samples/decorator.rb +0 -5
  140. data/spec/support/samples/decorator_with_allows.rb +0 -3
  141. data/spec/support/samples/decorator_with_denies.rb +0 -3
  142. data/spec/support/samples/decorator_with_denies_all.rb +0 -3
  143. data/spec/support/samples/decorator_with_multiple_allows.rb +0 -4
  144. data/spec/support/samples/decorator_with_special_methods.rb +0 -13
  145. data/spec/support/samples/namespaced_product_decorator.rb +0 -7
  146. data/spec/support/samples/product_decorator.rb +0 -7
  147. data/spec/support/samples/sequel_product.rb +0 -13
  148. data/spec/support/samples/some_thing.rb +0 -2
  149. data/spec/support/samples/some_thing_decorator.rb +0 -3
  150. /data/{performance → spec/performance}/active_record.rb +0 -0
  151. /data/{performance/bechmark.rb → spec/performance/benchmark.rb} +0 -0
  152. /data/{performance → spec/performance}/models.rb +0 -0
  153. /data/spec/support/{samples → decorators}/widget_decorator.rb +0 -0
  154. /data/spec/support/{samples → models}/widget.rb +0 -0
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,34 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Print deprecation notices to the Rails logger
17
+ config.active_support.deprecation = :log
18
+
19
+ # Only use best-standards-support built into browsers
20
+ config.action_dispatch.best_standards_support = :builtin
21
+
22
+ # Raise exception on mass assignment protection for Active Record models
23
+ config.active_record.mass_assignment_sanitizer = :strict
24
+
25
+ # Log the query plan for queries taking more than this (works
26
+ # with SQLite, MySQL, and PostgreSQL)
27
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
28
+
29
+ # Do not compress assets
30
+ config.assets.compress = false
31
+
32
+ # Expands the lines which load the assets
33
+ config.assets.debug = true
34
+ end
@@ -0,0 +1,55 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Defaults to nil and saved in location specified by config.assets.prefix
15
+ # config.assets.manifest = YOUR_PATH
16
+
17
+ # Specifies the header that your server uses for sending files
18
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
19
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
20
+
21
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
22
+ # config.force_ssl = true
23
+
24
+ # See everything in the log (default is :info)
25
+ # config.log_level = :debug
26
+
27
+ # Prepend all log lines with the following tags
28
+ # config.log_tags = [ :subdomain, :uuid ]
29
+
30
+ # Use a different logger for distributed setups
31
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
32
+
33
+ # Use a different cache store in production
34
+ # config.cache_store = :mem_cache_store
35
+
36
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
37
+ # config.action_controller.asset_host = "http://assets.example.com"
38
+
39
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
40
+ # config.assets.precompile += %w( search.js )
41
+
42
+ # Enable threaded mode
43
+ # config.threadsafe!
44
+
45
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
46
+ # the I18n.default_locale when a translation can not be found)
47
+ config.i18n.fallbacks = true
48
+
49
+ # Send deprecation notices to registered listeners
50
+ config.active_support.deprecation = :notify
51
+
52
+ # Log the query plan for queries taking more than this (works
53
+ # with SQLite, MySQL, and PostgreSQL)
54
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
55
+ end
@@ -0,0 +1,32 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Raise exception on mass assignment protection for Active Record models
28
+ config.active_record.mass_assignment_sanitizer = :strict
29
+
30
+ # Print deprecation notices to the stderr
31
+ config.active_support.deprecation = :stderr
32
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'c2e3474d3816f60bf6dd0f3b983e7283c7ff5373e11a96935340b544a31964dbe5ee077136165ee2975e0005f5e80207c0059e6d5589699031242ba5a06dcb87'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,7 @@
1
+ Dummy::Application.routes.draw do
2
+ scope "(:locale)", locale: /en|zh/ do
3
+ resources :posts, only: [:show] do
4
+ get "mail", on: :member
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,8 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
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 => 20121019115657) do
15
+
16
+ create_table "posts", :force => true do |t|
17
+ t.datetime "created_at", :null => false
18
+ t.datetime "updated_at", :null => false
19
+ end
20
+
21
+ end
@@ -0,0 +1,2 @@
1
+ Post.delete_all
2
+ Post.create id: 1
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ task "default" => "spec"
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe PostDecorator do
4
+ subject { PostDecorator.new(source) }
5
+ let(:source) { Post.create }
6
+
7
+ it "can use path helpers with its model" do
8
+ subject.path_with_model.should == "/en/posts/#{source.id}"
9
+ end
10
+
11
+ it "can use path helpers with its id" do
12
+ subject.path_with_id.should == "/en/posts/#{source.id}"
13
+ end
14
+
15
+ it "can use url helpers with its model" do
16
+ subject.url_with_model.should == "http://www.example.com/en/posts/#{source.id}"
17
+ end
18
+
19
+ it "can use url helpers with its id" do
20
+ subject.url_with_id.should == "http://www.example.com/en/posts/#{source.id}"
21
+ end
22
+
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe PostMailer do
4
+ describe "#decorated_email" do
5
+ subject { Capybara.string(email.body.to_s) }
6
+ let(:email) { PostMailer.decorated_email(post).deliver }
7
+ let(:post) { Post.create }
8
+
9
+ it "decorates" do
10
+ subject.should have_content "Today"
11
+ end
12
+
13
+ it "can use path helpers with a model" do
14
+ subject.should have_css "#path_with_model", text: "/en/posts/#{post.id}"
15
+ end
16
+
17
+ it "can use path helpers with an id" do
18
+ subject.should have_css "#path_with_id", text: "/en/posts/#{post.id}"
19
+ end
20
+
21
+ it "can use url helpers with a model" do
22
+ subject.should have_css "#url_with_model", text: "http://www.example.com/en/posts/#{post.id}"
23
+ end
24
+
25
+ it "can use url helpers with an id" do
26
+ subject.should have_css "#url_with_id", text: "http://www.example.com/en/posts/#{post.id}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rspec/rails'
4
+ require 'draper/test/rspec_integration'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.order = :random
9
+ end
@@ -15,8 +15,7 @@ describe Rails::Generators::DecoratorGenerator do
15
15
  describe 'app/decorators/your_model_decorator.rb' do
16
16
  subject { file('app/decorators/your_model_decorator.rb') }
17
17
  it { should exist }
18
- it { should contain "class YourModelDecorator < Draper::Base" }
19
- it { should contain "decorates :your_model" }
18
+ it { should contain "class YourModelDecorator < Draper::Decorator" }
20
19
  end
21
20
  end
22
21
 
@@ -31,12 +30,12 @@ describe Rails::Generators::DecoratorGenerator do
31
30
  end
32
31
 
33
32
  context 'parent decorator' do
34
- describe 'decorator inhereted from Draper::Base' do
33
+ describe 'decorator inhereted from Draper::Decorator' do
35
34
  before { run_generator ["YourModel"] }
36
35
 
37
36
  subject { file('app/decorators/your_model_decorator.rb') }
38
37
  it { should exist }
39
- it { should contain "class YourModelDecorator < Draper::Base" }
38
+ it { should contain "class YourModelDecorator < Draper::Decorator" }
40
39
  end
41
40
 
42
41
  describe "decorator inhereted from ApplicationDecorator if it's present" do
@@ -65,7 +64,17 @@ describe Rails::Generators::DecoratorGenerator do
65
64
  end
66
65
  end
67
66
 
68
- context 'using rspec' do
67
+ context 'using rspec with namespaced model' do
68
+ before { run_generator ["Namespace::YourModel", "-t=rspec"] }
69
+
70
+ describe 'spec/decorators/your_model_decorator_spec.rb' do
71
+ subject { file('spec/decorators/namespace/your_model_decorator_spec.rb') }
72
+ it { should exist }
73
+ it { should contain "describe Namespace::YourModelDecorator" }
74
+ end
75
+ end
76
+
77
+ context 'using test-unit' do
69
78
  before { run_generator ["YourModel", "-t=test_unit"] }
70
79
 
71
80
  describe 'test/decorators/YourModel_decorator_test.rb' do
@@ -74,4 +83,14 @@ describe Rails::Generators::DecoratorGenerator do
74
83
  it { should contain "class YourModelDecoratorTest < ActiveSupport::TestCase" }
75
84
  end
76
85
  end
86
+
87
+ context 'using test-unit with namespaced model' do
88
+ before { run_generator ["Namespace::YourModel", "-t=test_unit"] }
89
+
90
+ describe 'test/decorators/your_model_decorator_test.rb' do
91
+ subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
92
+ it { should exist }
93
+ it { should contain "class Namespace::YourModelDecoratorTest < ActiveSupport::TestCase" }
94
+ end
95
+ end
77
96
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'support/dummy_app'
3
+ require 'support/matchers/have_text'
4
+
5
+ app = DummyApp.new(ENV["RAILS_ENV"])
6
+
7
+ app.start_server do
8
+ {view: "/posts/1", mailer: "/posts/1/mail"}.each do |type, path|
9
+ page = app.get(path)
10
+
11
+ describe "in a #{type}" do
12
+ it "runs in the correct environment" do
13
+ page.should have_text(app.environment).in("#environment")
14
+ end
15
+
16
+ it "can use path helpers with a model" do
17
+ page.should have_text("/en/posts/1").in("#path_with_model")
18
+ end
19
+
20
+ it "can use path helpers with an id" do
21
+ page.should have_text("/en/posts/1").in("#path_with_id")
22
+ end
23
+
24
+ it "can use url helpers with a model" do
25
+ page.should have_text("http://www.example.com/en/posts/1").in("#url_with_model")
26
+ end
27
+
28
+ it "can use url helpers with an id" do
29
+ page.should have_text("http://www.example.com/en/posts/1").in("#url_with_id")
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'minitest/rails/active_support'
3
+ require 'draper/test/minitest_integration'
4
+
5
+ describe "minitest-rails spec_type Lookup Integration" do
6
+ context "ProductDecorator" do
7
+ it "resolves constants" do
8
+ klass = MiniTest::Spec.spec_type(ProductDecorator)
9
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
10
+ end
11
+
12
+ it "resolves strings" do
13
+ klass = MiniTest::Spec.spec_type("ProductDecorator")
14
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
15
+ end
16
+ end
17
+
18
+ context "WidgetDecorator" do
19
+ it "resolves constants" do
20
+ klass = MiniTest::Spec.spec_type(WidgetDecorator)
21
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
22
+ end
23
+
24
+ it "resolves strings" do
25
+ klass = MiniTest::Spec.spec_type("WidgetDecorator")
26
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
27
+ end
28
+ end
29
+
30
+ context "decorator strings" do
31
+ it "resolves DoesNotExistDecorator" do
32
+ klass = MiniTest::Spec.spec_type("DoesNotExistDecorator")
33
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
34
+ end
35
+
36
+ it "resolves DoesNotExistDecoratorTest" do
37
+ klass = MiniTest::Spec.spec_type("DoesNotExistDecoratorTest")
38
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
39
+ end
40
+
41
+ it "resolves Does Not Exist Decorator" do
42
+ klass = MiniTest::Spec.spec_type("Does Not Exist Decorator")
43
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
44
+ end
45
+
46
+ it "resolves Does Not Exist Decorator Test" do
47
+ klass = MiniTest::Spec.spec_type("Does Not Exist Decorator Test")
48
+ klass.should == MiniTest::Rails::ActiveSupport::TestCase
49
+ end
50
+ end
51
+
52
+ context "non-decorators" do
53
+ it "doesn't resolve constants" do
54
+ klass = MiniTest::Spec.spec_type(Draper::HelperSupport)
55
+ klass.should == MiniTest::Spec
56
+ end
57
+
58
+ it "doesn't resolve strings" do
59
+ klass = MiniTest::Spec.spec_type("Nothing to see here...")
60
+ klass.should == MiniTest::Spec
61
+ end
62
+ end
63
+ end
@@ -1,6 +1,5 @@
1
1
  require "./performance/models"
2
- class ProductDecorator < Draper::Base
3
- decorates :product
2
+ class ProductDecorator < Draper::Decorator
4
3
 
5
4
  def awesome_title
6
5
  "Awesome Title"
@@ -21,8 +20,7 @@ class ProductDecorator < Draper::Base
21
20
 
22
21
  end
23
22
 
24
- class FastProductDecorator < Draper::Base
25
- decorates :product
23
+ class FastProductDecorator < Draper::Decorator
26
24
 
27
25
  def awesome_title
28
26
  "Awesome Title"