draper 0.18.0 → 1.0.0
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.
- data/.gitignore +3 -0
- data/.travis.yml +11 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +161 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +20 -0
- data/LICENSE +7 -0
- data/README.md +324 -0
- data/Rakefile +52 -31
- data/draper.gemspec +11 -9
- data/lib/draper/automatic_delegation.rb +50 -0
- data/lib/draper/collection_decorator.rb +107 -0
- data/lib/draper/decoratable.rb +83 -0
- data/lib/draper/decorated_association.rb +74 -0
- data/lib/draper/decorator.rb +238 -0
- data/lib/draper/delegation.rb +13 -0
- data/lib/draper/finders.rb +37 -0
- data/lib/draper/helper_proxy.rb +17 -0
- data/lib/draper/lazy_helpers.rb +10 -6
- data/lib/draper/railtie.rb +27 -21
- data/lib/draper/tasks/test.rake +22 -0
- data/lib/draper/test/devise_helper.rb +34 -0
- data/lib/draper/test/minitest_integration.rb +2 -3
- data/lib/draper/test/rspec_integration.rb +3 -13
- data/lib/draper/test_case.rb +33 -0
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +12 -17
- data/lib/draper/view_helpers.rb +37 -0
- data/lib/draper.rb +47 -8
- data/lib/generators/decorator/decorator_generator.rb +10 -2
- data/lib/generators/decorator/templates/decorator.rb +12 -27
- data/lib/generators/mini_test/decorator_generator.rb +20 -0
- data/lib/generators/mini_test/templates/decorator_spec.rb +4 -0
- data/lib/generators/mini_test/templates/decorator_test.rb +4 -0
- data/lib/generators/test_unit/templates/decorator_test.rb +1 -1
- data/spec/draper/collection_decorator_spec.rb +286 -0
- data/spec/draper/decoratable_spec.rb +192 -0
- data/spec/draper/decorated_association_spec.rb +142 -0
- data/spec/draper/decorator_spec.rb +624 -0
- data/spec/draper/finders_spec.rb +132 -0
- data/spec/draper/helper_proxy_spec.rb +12 -0
- data/spec/draper/view_helpers_spec.rb +41 -0
- data/spec/dummy/.rspec +2 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/localized_urls.rb +5 -0
- data/spec/dummy/app/controllers/posts_controller.rb +11 -0
- data/spec/dummy/app/decorators/post_decorator.rb +32 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +3 -0
- data/spec/dummy/app/mailers/post_mailer.rb +9 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +11 -0
- data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +1 -0
- data/spec/dummy/app/views/posts/_post.html.erb +19 -0
- data/spec/dummy/app/views/posts/show.html.erb +1 -0
- data/spec/dummy/config/application.rb +64 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +34 -0
- data/spec/dummy/config/environments/production.rb +55 -0
- data/spec/dummy/config/environments/test.rb +32 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +8 -0
- data/spec/dummy/db/schema.rb +21 -0
- data/spec/dummy/db/seeds.rb +2 -0
- data/spec/dummy/lib/tasks/test.rake +10 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/mini_test/mini_test_integration_test.rb +46 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +26 -0
- data/spec/dummy/spec/decorators/rspec_integration_spec.rb +19 -0
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +29 -0
- data/spec/dummy/spec/models/post_spec.rb +14 -0
- data/spec/dummy/spec/spec_helper.rb +8 -0
- data/spec/generators/decorator/decorator_generator_spec.rb +47 -7
- data/spec/integration/integration_spec.rb +33 -0
- data/{performance → spec/performance}/decorators.rb +2 -4
- data/spec/spec_helper.rb +20 -45
- data/spec/support/action_controller.rb +12 -0
- data/spec/support/active_model.rb +7 -0
- data/spec/support/active_record.rb +9 -0
- data/spec/support/{samples → decorators}/decorator_with_application_helper.rb +1 -1
- data/spec/support/decorators/namespaced_product_decorator.rb +5 -0
- data/spec/support/decorators/non_active_model_product_decorator.rb +2 -0
- data/spec/support/decorators/product_decorator.rb +23 -0
- data/spec/support/{samples → decorators}/products_decorator.rb +1 -1
- data/spec/support/decorators/some_thing_decorator.rb +2 -0
- data/spec/support/{samples → decorators}/specific_product_decorator.rb +0 -2
- data/spec/support/dummy_app.rb +85 -0
- data/spec/support/matchers/have_text.rb +50 -0
- data/spec/support/{samples → models}/namespaced_product.rb +1 -3
- data/spec/support/{samples → models}/non_active_model_product.rb +1 -0
- data/spec/support/{samples → models}/product.rb +17 -2
- data/spec/support/models/some_thing.rb +5 -0
- data/spec/support/models/uninferrable_decorator_model.rb +3 -0
- metadata +241 -87
- data/CHANGELOG.markdown +0 -57
- data/Readme.markdown +0 -387
- data/lib/draper/active_model_support.rb +0 -27
- data/lib/draper/base.rb +0 -312
- data/lib/draper/decorated_enumerable_proxy.rb +0 -90
- data/lib/draper/model_support.rb +0 -25
- data/lib/draper/rspec_integration.rb +0 -2
- data/lib/draper/system.rb +0 -18
- data/spec/draper/base_spec.rb +0 -873
- data/spec/draper/decorated_enumerable_proxy_spec.rb +0 -45
- data/spec/draper/model_support_spec.rb +0 -48
- data/spec/minitest-rails/spec_type_spec.rb +0 -63
- data/spec/support/samples/active_record.rb +0 -17
- data/spec/support/samples/decorator.rb +0 -5
- data/spec/support/samples/decorator_with_allows.rb +0 -3
- data/spec/support/samples/decorator_with_denies.rb +0 -3
- data/spec/support/samples/decorator_with_denies_all.rb +0 -3
- data/spec/support/samples/decorator_with_multiple_allows.rb +0 -4
- data/spec/support/samples/decorator_with_special_methods.rb +0 -13
- data/spec/support/samples/enumerable_proxy.rb +0 -3
- data/spec/support/samples/namespaced_product_decorator.rb +0 -7
- data/spec/support/samples/product_decorator.rb +0 -7
- data/spec/support/samples/sequel_product.rb +0 -13
- data/spec/support/samples/some_thing.rb +0 -2
- data/spec/support/samples/some_thing_decorator.rb +0 -3
- /data/{performance → spec/performance}/active_record.rb +0 -0
- /data/{performance/bechmark.rb → spec/performance/benchmark.rb} +0 -0
- /data/{performance → spec/performance}/models.rb +0 -0
- /data/spec/support/{samples → decorators}/widget_decorator.rb +0 -0
- /data/spec/support/{samples → models}/widget.rb +0 -0
|
@@ -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,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,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
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
2
|
+
require 'minitest/autorun'
|
|
3
|
+
require 'minitest/rails'
|
|
4
|
+
|
|
5
|
+
def it_is_a_decorator_test
|
|
6
|
+
it "is a decorator test" do
|
|
7
|
+
assert_kind_of Draper::TestCase, self
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def it_is_not_a_decorator_test
|
|
12
|
+
it "is not a decorator test" do
|
|
13
|
+
refute_kind_of Draper::TestCase, self
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
ProductDecorator = Class.new(Draper::Decorator)
|
|
18
|
+
ProductsDecorator = Class.new(Draper::CollectionDecorator)
|
|
19
|
+
|
|
20
|
+
describe ProductDecorator do
|
|
21
|
+
it_is_a_decorator_test
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe ProductsDecorator do
|
|
25
|
+
it_is_a_decorator_test
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "ProductDecorator" do
|
|
29
|
+
it_is_a_decorator_test
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "AnyDecorator" do
|
|
33
|
+
it_is_a_decorator_test
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "Any decorator test" do
|
|
37
|
+
it_is_a_decorator_test
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe Object do
|
|
41
|
+
it_is_not_a_decorator_test
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "Nope" do
|
|
45
|
+
it_is_not_a_decorator_test
|
|
46
|
+
end
|
|
@@ -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,26 @@
|
|
|
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:12345/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:12345/en/posts/#{source.id}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "can be passed implicitly to url_for" do
|
|
24
|
+
subject.link.should == "<a href=\"/en/posts/#{source.id}\">#{source.id}</a>"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
describe "A spec in this folder" do
|
|
2
|
+
it "is a decorator spec" do
|
|
3
|
+
example.metadata[:type].should be :decorator
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe "A decorator spec" do
|
|
8
|
+
it "can access helpers through `helper`" do
|
|
9
|
+
helper.content_tag(:p, "Help!").should == "<p>Help!</p>"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "can access helpers through `helpers`" do
|
|
13
|
+
helpers.content_tag(:p, "Help!").should == "<p>Help!</p>"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "can access helpers through `h`" do
|
|
17
|
+
h.content_tag(:p, "Help!").should == "<p>Help!</p>"
|
|
18
|
+
end
|
|
19
|
+
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:12345/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:12345/en/posts/#{post.id}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Post do
|
|
4
|
+
describe "#==" do
|
|
5
|
+
before { Post.create }
|
|
6
|
+
subject { Post.first }
|
|
7
|
+
|
|
8
|
+
it "is true for other instances' decorators" do
|
|
9
|
+
other = Post.first
|
|
10
|
+
subject.should_not be other
|
|
11
|
+
(subject == other.decorate).should be_true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
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::
|
|
19
|
-
it { should contain "decorates :your_model" }
|
|
18
|
+
it { should contain "class YourModelDecorator < Draper::Decorator" }
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
21
|
|
|
@@ -31,15 +30,15 @@ describe Rails::Generators::DecoratorGenerator do
|
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
context 'parent decorator' do
|
|
34
|
-
describe 'decorator
|
|
33
|
+
describe 'decorator inherited 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::
|
|
38
|
+
it { should contain "class YourModelDecorator < Draper::Decorator" }
|
|
40
39
|
end
|
|
41
40
|
|
|
42
|
-
describe "decorator
|
|
41
|
+
describe "decorator inherited from ApplicationDecorator if it's present" do
|
|
43
42
|
before do
|
|
44
43
|
class ApplicationDecorator; end
|
|
45
44
|
run_generator ["YourModel"]
|
|
@@ -81,7 +80,7 @@ describe Rails::Generators::DecoratorGenerator do
|
|
|
81
80
|
describe 'test/decorators/YourModel_decorator_test.rb' do
|
|
82
81
|
subject { file('test/decorators/your_model_decorator_test.rb') }
|
|
83
82
|
it { should exist }
|
|
84
|
-
it { should contain "class YourModelDecoratorTest <
|
|
83
|
+
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
|
85
84
|
end
|
|
86
85
|
end
|
|
87
86
|
|
|
@@ -91,7 +90,48 @@ describe Rails::Generators::DecoratorGenerator do
|
|
|
91
90
|
describe 'test/decorators/your_model_decorator_test.rb' do
|
|
92
91
|
subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
|
|
93
92
|
it { should exist }
|
|
94
|
-
it { should contain "class Namespace::YourModelDecoratorTest <
|
|
93
|
+
it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
|
95
94
|
end
|
|
96
95
|
end
|
|
96
|
+
|
|
97
|
+
context 'using minitest-rails' do
|
|
98
|
+
before { run_generator ["YourModel", "-t=mini_test"] }
|
|
99
|
+
|
|
100
|
+
describe 'test/decorators/your_model_decorator_test.rb' do
|
|
101
|
+
subject { file('test/decorators/your_model_decorator_test.rb') }
|
|
102
|
+
it { should exist }
|
|
103
|
+
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'using minitest-rails with namespaced model' do
|
|
108
|
+
before { run_generator ["Namespace::YourModel", "-t=mini_test"] }
|
|
109
|
+
|
|
110
|
+
describe 'test/decorators/your_model_decorator_test.rb' do
|
|
111
|
+
subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
|
|
112
|
+
it { should exist }
|
|
113
|
+
it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context 'using minitest-rails with spec syntax' do
|
|
118
|
+
before { run_generator ["YourModel", "-t=mini_test", "--spec"] }
|
|
119
|
+
|
|
120
|
+
describe 'test/decorators/your_model_decorator_test.rb' do
|
|
121
|
+
subject { file('test/decorators/your_model_decorator_test.rb') }
|
|
122
|
+
it { should exist }
|
|
123
|
+
it { should contain "describe YourModelDecorator" }
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context 'using minitest-rails with spec syntax with namespaced model' do
|
|
128
|
+
before { run_generator ["Namespace::YourModel", "-t=mini_test", "--spec"] }
|
|
129
|
+
|
|
130
|
+
describe 'test/decorators/your_model_decorator_test.rb' do
|
|
131
|
+
subject { file('test/decorators/namespace/your_model_decorator_test.rb') }
|
|
132
|
+
it { should exist }
|
|
133
|
+
it { should contain "describe Namespace::YourModelDecorator" }
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
97
137
|
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:12345/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:12345/en/posts/1").in("#url_with_id")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require "./performance/models"
|
|
2
|
-
class ProductDecorator < Draper::
|
|
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::
|
|
25
|
-
decorates :product
|
|
23
|
+
class FastProductDecorator < Draper::Decorator
|
|
26
24
|
|
|
27
25
|
def awesome_title
|
|
28
26
|
"Awesome Title"
|