draper 0.18.0 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.markdown +8 -0
- data/Gemfile +4 -0
- data/Rakefile +50 -31
- data/Readme.markdown +42 -48
- data/draper.gemspec +2 -1
- data/lib/draper.rb +42 -7
- data/lib/draper/collection_decorator.rb +88 -0
- data/lib/draper/decoratable.rb +44 -0
- data/lib/draper/decorated_association.rb +55 -0
- data/lib/draper/decorator.rb +208 -0
- data/lib/draper/finders.rb +44 -0
- data/lib/draper/helper_proxy.rb +16 -0
- data/lib/draper/railtie.rb +17 -21
- data/lib/draper/security.rb +48 -0
- data/lib/draper/tasks/tu.rake +5 -0
- data/lib/draper/test/minitest_integration.rb +1 -1
- data/lib/draper/test/test_unit_integration.rb +9 -0
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +6 -13
- data/lib/draper/view_helpers.rb +36 -0
- data/lib/generators/decorator/decorator_generator.rb +1 -1
- data/lib/generators/decorator/templates/decorator.rb +0 -1
- data/spec/draper/collection_decorator_spec.rb +240 -0
- data/spec/draper/decoratable_spec.rb +164 -0
- data/spec/draper/decorated_association_spec.rb +130 -0
- data/spec/draper/decorator_spec.rb +497 -0
- data/spec/draper/finders_spec.rb +156 -0
- data/spec/draper/helper_proxy_spec.rb +12 -0
- data/spec/draper/security_spec.rb +158 -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 +17 -0
- data/spec/dummy/app/decorators/post_decorator.rb +25 -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.ru +4 -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/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +7 -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/spec.rake +5 -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 +23 -0
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +29 -0
- data/spec/dummy/spec/spec_helper.rb +9 -0
- data/spec/generators/decorator/decorator_generator_spec.rb +3 -4
- data/spec/integration/integration_spec.rb +33 -0
- data/{performance → spec/performance}/active_record.rb +0 -0
- data/{performance/bechmark.rb → spec/performance/benchmark.rb} +0 -0
- data/{performance → spec/performance}/decorators.rb +2 -4
- data/{performance → spec/performance}/models.rb +0 -0
- data/spec/spec_helper.rb +20 -41
- data/spec/support/action_controller.rb +12 -0
- data/spec/support/active_model.rb +7 -0
- data/spec/support/{samples/active_record.rb → active_record.rb} +5 -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 +19 -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/{samples → decorators}/widget_decorator.rb +0 -0
- data/spec/support/dummy_app.rb +84 -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 +13 -2
- data/spec/support/models/some_thing.rb +5 -0
- data/spec/support/models/uninferrable_decorator_model.rb +3 -0
- data/spec/support/{samples → models}/widget.rb +0 -0
- metadata +185 -68
- 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/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
@@ -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,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::
|
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::
|
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::
|
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
|
@@ -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
|
File without changes
|
File without changes
|
@@ -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"
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -3,51 +3,30 @@ require 'ammeter/init'
|
|
3
3
|
require 'rails'
|
4
4
|
|
5
5
|
require 'action_view'
|
6
|
-
Bundler.require
|
7
|
-
|
8
|
-
require './spec/support/samples/active_record'
|
9
|
-
require './spec/support/samples/decorator'
|
10
|
-
require './spec/support/samples/decorator_with_allows'
|
11
|
-
require './spec/support/samples/decorator_with_multiple_allows'
|
12
|
-
require './spec/support/samples/decorator_with_application_helper'
|
13
|
-
require './spec/support/samples/decorator_with_denies'
|
14
|
-
require './spec/support/samples/decorator_with_denies_all'
|
15
|
-
require './spec/support/samples/decorator_with_special_methods'
|
16
|
-
require './spec/support/samples/enumerable_proxy'
|
17
|
-
require './spec/support/samples/namespaced_product'
|
18
|
-
require './spec/support/samples/namespaced_product_decorator'
|
19
|
-
require './spec/support/samples/non_active_model_product'
|
20
|
-
require './spec/support/samples/product'
|
21
|
-
require './spec/support/samples/product_decorator'
|
22
|
-
require './spec/support/samples/products_decorator'
|
23
|
-
require './spec/support/samples/sequel_product'
|
24
|
-
require './spec/support/samples/specific_product_decorator'
|
25
|
-
require './spec/support/samples/some_thing'
|
26
|
-
require './spec/support/samples/some_thing_decorator'
|
27
|
-
require './spec/support/samples/widget'
|
28
|
-
require './spec/support/samples/widget_decorator'
|
29
|
-
|
30
6
|
require 'action_controller'
|
31
7
|
require 'action_controller/test_case'
|
32
8
|
|
33
|
-
|
34
|
-
class Base
|
35
|
-
Draper::System.setup_action_controller(self)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module ActiveRecord
|
40
|
-
class Relation
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class ApplicationController < ActionController::Base
|
45
|
-
def hello_world
|
46
|
-
"Hello, World!"
|
47
|
-
end
|
48
|
-
helper_method :hello_world
|
49
|
-
end
|
9
|
+
Bundler.require
|
50
10
|
|
11
|
+
require './spec/support/active_model'
|
12
|
+
require './spec/support/active_record'
|
13
|
+
require './spec/support/action_controller'
|
14
|
+
|
15
|
+
require './spec/support/models/product'
|
16
|
+
require './spec/support/models/namespaced_product'
|
17
|
+
require './spec/support/models/non_active_model_product'
|
18
|
+
require './spec/support/models/widget'
|
19
|
+
require './spec/support/models/some_thing'
|
20
|
+
require './spec/support/models/uninferrable_decorator_model'
|
21
|
+
|
22
|
+
require './spec/support/decorators/product_decorator'
|
23
|
+
require './spec/support/decorators/namespaced_product_decorator'
|
24
|
+
require './spec/support/decorators/non_active_model_product_decorator'
|
25
|
+
require './spec/support/decorators/widget_decorator'
|
26
|
+
require './spec/support/decorators/specific_product_decorator'
|
27
|
+
require './spec/support/decorators/products_decorator'
|
28
|
+
require './spec/support/decorators/some_thing_decorator'
|
29
|
+
require './spec/support/decorators/decorator_with_application_helper'
|
51
30
|
|
52
31
|
class << Rails
|
53
32
|
undef application # Avoid silly Rails bug: https://github.com/rails/rails/pull/6429
|