draper_new 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +230 -0
- data/CONTRIBUTING.md +20 -0
- data/Gemfile +16 -0
- data/Guardfile +26 -0
- data/LICENSE +7 -0
- data/README.md +587 -0
- data/Rakefile +69 -0
- data/draper_new.gemspec +31 -0
- data/gemfiles/4.0.gemfile +3 -0
- data/gemfiles/4.1.gemfile +3 -0
- data/gemfiles/4.2.6.gemfile +3 -0
- data/gemfiles/4.2.gemfile +3 -0
- data/lib/draper.rb +63 -0
- data/lib/draper/automatic_delegation.rb +56 -0
- data/lib/draper/collection_decorator.rb +100 -0
- data/lib/draper/decoratable.rb +96 -0
- data/lib/draper/decoratable/equality.rb +26 -0
- data/lib/draper/decorated_association.rb +35 -0
- data/lib/draper/decorates_assigned.rb +44 -0
- data/lib/draper/decorator.rb +293 -0
- data/lib/draper/delegation.rb +13 -0
- data/lib/draper/factory.rb +91 -0
- data/lib/draper/finders.rb +37 -0
- data/lib/draper/helper_proxy.rb +44 -0
- data/lib/draper/helper_support.rb +5 -0
- data/lib/draper/lazy_helpers.rb +15 -0
- data/lib/draper/railtie.rb +70 -0
- data/lib/draper/tasks/test.rake +22 -0
- data/lib/draper/test/devise_helper.rb +30 -0
- data/lib/draper/test/minitest_integration.rb +6 -0
- data/lib/draper/test/rspec_integration.rb +20 -0
- data/lib/draper/test_case.rb +42 -0
- data/lib/draper/undecorate.rb +9 -0
- data/lib/draper/version.rb +3 -0
- data/lib/draper/view_context.rb +104 -0
- data/lib/draper/view_context/build_strategy.rb +48 -0
- data/lib/draper/view_helpers.rb +37 -0
- data/lib/generators/controller_override.rb +17 -0
- 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/rails/decorator_generator.rb +36 -0
- data/lib/generators/rails/templates/decorator.rb +19 -0
- data/lib/generators/rspec/decorator_generator.rb +9 -0
- data/lib/generators/rspec/templates/decorator_spec.rb +4 -0
- data/lib/generators/test_unit/decorator_generator.rb +9 -0
- data/lib/generators/test_unit/templates/decorator_test.rb +4 -0
- data/spec/draper/collection_decorator_spec.rb +307 -0
- data/spec/draper/decoratable/equality_spec.rb +10 -0
- data/spec/draper/decoratable_spec.rb +202 -0
- data/spec/draper/decorated_association_spec.rb +84 -0
- data/spec/draper/decorates_assigned_spec.rb +71 -0
- data/spec/draper/decorator_spec.rb +816 -0
- data/spec/draper/factory_spec.rb +251 -0
- data/spec/draper/finders_spec.rb +166 -0
- data/spec/draper/helper_proxy_spec.rb +61 -0
- data/spec/draper/lazy_helpers_spec.rb +21 -0
- data/spec/draper/undecorate_spec.rb +19 -0
- data/spec/draper/view_context/build_strategy_spec.rb +116 -0
- data/spec/draper/view_context_spec.rb +154 -0
- data/spec/draper/view_helpers_spec.rb +8 -0
- data/spec/dummy/.rspec +2 -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 +20 -0
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +4 -0
- data/spec/dummy/app/decorators/post_decorator.rb +60 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/mailers/application_mailer.rb +3 -0
- data/spec/dummy/app/mailers/post_mailer.rb +19 -0
- data/spec/dummy/app/models/admin.rb +5 -0
- data/spec/dummy/app/models/mongoid_post.rb +5 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +5 -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 +40 -0
- data/spec/dummy/app/views/posts/show.html.erb +1 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +71 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +33 -0
- data/spec/dummy/config/environments/production.rb +57 -0
- data/spec/dummy/config/environments/test.rb +31 -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 +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/mongoid.yml +79 -0
- data/spec/dummy/config/routes.rb +9 -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/fast_spec/post_decorator_spec.rb +37 -0
- data/spec/dummy/lib/tasks/test.rake +16 -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/active_model_serializers_spec.rb +16 -0
- data/spec/dummy/spec/decorators/devise_spec.rb +64 -0
- data/spec/dummy/spec/decorators/helpers_spec.rb +21 -0
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +66 -0
- data/spec/dummy/spec/decorators/spec_type_spec.rb +7 -0
- data/spec/dummy/spec/decorators/view_context_spec.rb +22 -0
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +33 -0
- data/spec/dummy/spec/models/mongoid_post_spec.rb +8 -0
- data/spec/dummy/spec/models/post_spec.rb +6 -0
- data/spec/dummy/spec/shared_examples/decoratable.rb +24 -0
- data/spec/dummy/spec/spec_helper.rb +8 -0
- data/spec/dummy/test/decorators/minitest/devise_test.rb +64 -0
- data/spec/dummy/test/decorators/minitest/helpers_test.rb +21 -0
- data/spec/dummy/test/decorators/minitest/spec_type_test.rb +52 -0
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +24 -0
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +64 -0
- data/spec/dummy/test/decorators/test_unit/helpers_test.rb +21 -0
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +24 -0
- data/spec/dummy/test/minitest_helper.rb +2 -0
- data/spec/dummy/test/test_helper.rb +3 -0
- data/spec/generators/controller/controller_generator_spec.rb +22 -0
- data/spec/generators/decorator/decorator_generator_spec.rb +92 -0
- data/spec/integration/integration_spec.rb +66 -0
- data/spec/performance/active_record.rb +4 -0
- data/spec/performance/benchmark.rb +55 -0
- data/spec/performance/decorators.rb +45 -0
- data/spec/performance/models.rb +20 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/dummy_app.rb +85 -0
- data/spec/support/matchers/have_text.rb +50 -0
- data/spec/support/shared_examples/decoratable_equality.rb +40 -0
- data/spec/support/shared_examples/view_helpers.rb +39 -0
- metadata +420 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
shared_examples_for "a decoratable model" do
|
2
|
+
describe ".decorate" do
|
3
|
+
it "applies a collection decorator to a scope" do
|
4
|
+
described_class.create
|
5
|
+
decorated = described_class.limit(1).decorate
|
6
|
+
|
7
|
+
expect(decorated.size).to eq(1)
|
8
|
+
expect(decorated).to be_decorated
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#==" do
|
13
|
+
it "is true for other instances' decorators" do
|
14
|
+
pending "Mongoid < 3.1 overrides `#==`" if defined?(Mongoid) && Mongoid::VERSION.to_f < 3.1 && described_class < Mongoid::Document
|
15
|
+
|
16
|
+
described_class.create
|
17
|
+
one = described_class.first
|
18
|
+
other = described_class.first
|
19
|
+
|
20
|
+
expect(one).not_to be other
|
21
|
+
expect(one == other.decorate).to be_truthy
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
if defined?(Devise)
|
4
|
+
describe "A decorator test" do
|
5
|
+
it "can sign in a real user" do
|
6
|
+
user = User.new
|
7
|
+
sign_in user
|
8
|
+
|
9
|
+
assert_same user, helper.current_user
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can sign in a mock user" do
|
13
|
+
user = Object.new
|
14
|
+
sign_in :user, user
|
15
|
+
|
16
|
+
assert_same user, helper.current_user
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can sign in a real admin" do
|
20
|
+
admin = Admin.new
|
21
|
+
sign_in admin
|
22
|
+
|
23
|
+
assert_same admin, helper.current_admin
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can sign in a mock admin" do
|
27
|
+
admin = Object.new
|
28
|
+
sign_in :admin, admin
|
29
|
+
|
30
|
+
assert_same admin, helper.current_admin
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can sign out a real user" do
|
34
|
+
user = User.new
|
35
|
+
sign_in user
|
36
|
+
sign_out user
|
37
|
+
|
38
|
+
assert helper.current_user.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can sign out a mock user" do
|
42
|
+
user = Object.new
|
43
|
+
sign_in :user, user
|
44
|
+
sign_out :user
|
45
|
+
|
46
|
+
assert helper.current_user.nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can sign out without a user" do
|
50
|
+
sign_out :user
|
51
|
+
|
52
|
+
assert helper.current_user.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
it "is backwards-compatible" do
|
56
|
+
user = Object.new
|
57
|
+
ActiveSupport::Deprecation.silence do
|
58
|
+
sign_in user
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_same user, helper.current_user
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe "A decorator test" do
|
4
|
+
it "can access helpers through `helper`" do
|
5
|
+
assert_equal "<p>Help!</p>", helper.content_tag(:p, "Help!")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "can access helpers through `helpers`" do
|
9
|
+
assert_equal "<p>Help!</p>", helpers.content_tag(:p, "Help!")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can access helpers through `h`" do
|
13
|
+
assert_equal "<p>Help!</p>", h.content_tag(:p, "Help!")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "gets the same helper object as a decorator" do
|
17
|
+
decorator = Draper::Decorator.new(Object.new)
|
18
|
+
|
19
|
+
assert_same decorator.helpers, helpers
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
def it_is_a_decorator_test
|
4
|
+
it "is a decorator test" do
|
5
|
+
assert_kind_of Draper::TestCase, self
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def it_is_not_a_decorator_test
|
10
|
+
it "is not a decorator test" do
|
11
|
+
refute_kind_of Draper::TestCase, self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ProductDecorator = Class.new(Draper::Decorator)
|
16
|
+
ProductsDecorator = Class.new(Draper::CollectionDecorator)
|
17
|
+
|
18
|
+
describe ProductDecorator do
|
19
|
+
it_is_a_decorator_test
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ProductsDecorator do
|
23
|
+
it_is_a_decorator_test
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "ProductDecorator" do
|
27
|
+
it_is_a_decorator_test
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "AnyDecorator" do
|
31
|
+
it_is_a_decorator_test
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Any decorator" do
|
35
|
+
it_is_a_decorator_test
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "AnyDecoratorTest" do
|
39
|
+
it_is_a_decorator_test
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "Any decorator test" do
|
43
|
+
it_is_a_decorator_test
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Object do
|
47
|
+
it_is_not_a_decorator_test
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "Nope" do
|
51
|
+
it_is_not_a_decorator_test
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
def it_does_not_leak_view_context
|
4
|
+
2.times do
|
5
|
+
it "has an independent view context" do
|
6
|
+
refute_equal :leaked, Draper::ViewContext.current
|
7
|
+
Draper::ViewContext.current = :leaked
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "A decorator test" do
|
13
|
+
it_does_not_leak_view_context
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "A controller test" do
|
17
|
+
tests Class.new(ActionController::Base)
|
18
|
+
|
19
|
+
it_does_not_leak_view_context
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "A mailer test" do
|
23
|
+
it_does_not_leak_view_context
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
if defined?(Devise)
|
4
|
+
class DeviseTest < Draper::TestCase
|
5
|
+
def test_sign_in_a_real_user
|
6
|
+
user = User.new
|
7
|
+
sign_in user
|
8
|
+
|
9
|
+
assert_same user, helper.current_user
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_sign_in_a_mock_user
|
13
|
+
user = Object.new
|
14
|
+
sign_in :user, user
|
15
|
+
|
16
|
+
assert_same user, helper.current_user
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_sign_in_a_real_admin
|
20
|
+
admin = Admin.new
|
21
|
+
sign_in admin
|
22
|
+
|
23
|
+
assert_same admin, helper.current_admin
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_sign_in_a_mock_admin
|
27
|
+
admin = Object.new
|
28
|
+
sign_in :admin, admin
|
29
|
+
|
30
|
+
assert_same admin, helper.current_admin
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_sign_out_a_real_user
|
34
|
+
user = User.new
|
35
|
+
sign_in user
|
36
|
+
sign_out user
|
37
|
+
|
38
|
+
assert helper.current_user.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_sign_out_a_mock_user
|
42
|
+
user = Object.new
|
43
|
+
sign_in :user, user
|
44
|
+
sign_out :user
|
45
|
+
|
46
|
+
assert helper.current_user.nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_sign_out_without_a_user
|
50
|
+
sign_out :user
|
51
|
+
|
52
|
+
assert helper.current_user.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_backwards_compatibility
|
56
|
+
user = Object.new
|
57
|
+
ActiveSupport::Deprecation.silence do
|
58
|
+
sign_in user
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_same user, helper.current_user
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HelpersTest < Draper::TestCase
|
4
|
+
def test_access_helpers_through_helper
|
5
|
+
assert_equal "<p>Help!</p>", helper.content_tag(:p, "Help!")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_access_helpers_through_helpers
|
9
|
+
assert_equal "<p>Help!</p>", helpers.content_tag(:p, "Help!")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_access_helpers_through_h
|
13
|
+
assert_equal "<p>Help!</p>", h.content_tag(:p, "Help!")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_same_helper_object_as_decorators
|
17
|
+
decorator = Draper::Decorator.new(Object.new)
|
18
|
+
|
19
|
+
assert_same decorator.helpers, helpers
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
def it_does_not_leak_view_context
|
4
|
+
2.times do |n|
|
5
|
+
define_method("test_has_independent_view_context_#{n}") do
|
6
|
+
refute_equal :leaked, Draper::ViewContext.current
|
7
|
+
Draper::ViewContext.current = :leaked
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class DecoratorTest < Draper::TestCase
|
13
|
+
it_does_not_leak_view_context
|
14
|
+
end
|
15
|
+
|
16
|
+
class ControllerTest < ActionController::TestCase
|
17
|
+
tests Class.new(ActionController::Base)
|
18
|
+
|
19
|
+
it_does_not_leak_view_context
|
20
|
+
end
|
21
|
+
|
22
|
+
class MailerTest < ActionMailer::TestCase
|
23
|
+
it_does_not_leak_view_context
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rails'
|
3
|
+
require 'ammeter/init'
|
4
|
+
require 'generators/controller_override'
|
5
|
+
require 'generators/rails/decorator_generator'
|
6
|
+
|
7
|
+
describe Rails::Generators::ControllerGenerator do
|
8
|
+
destination File.expand_path("../tmp", __FILE__)
|
9
|
+
|
10
|
+
before { prepare_destination }
|
11
|
+
after(:all) { FileUtils.rm_rf destination_root }
|
12
|
+
|
13
|
+
describe "the generated decorator" do
|
14
|
+
subject { file("app/decorators/your_model_decorator.rb") }
|
15
|
+
|
16
|
+
describe "naming" do
|
17
|
+
before { run_generator %w(YourModels) }
|
18
|
+
|
19
|
+
it { should contain "class YourModelDecorator" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rails'
|
3
|
+
require 'ammeter/init'
|
4
|
+
require 'generators/rails/decorator_generator'
|
5
|
+
|
6
|
+
describe Rails::Generators::DecoratorGenerator do
|
7
|
+
destination File.expand_path("../tmp", __FILE__)
|
8
|
+
|
9
|
+
before { prepare_destination }
|
10
|
+
after(:all) { FileUtils.rm_rf destination_root }
|
11
|
+
|
12
|
+
describe "the generated decorator" do
|
13
|
+
subject { file("app/decorators/your_model_decorator.rb") }
|
14
|
+
|
15
|
+
describe "naming" do
|
16
|
+
before { run_generator %w(YourModel) }
|
17
|
+
|
18
|
+
it { should contain "class YourModelDecorator" }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "namespacing" do
|
22
|
+
subject { file("app/decorators/namespace/your_model_decorator.rb") }
|
23
|
+
before { run_generator %w(Namespace::YourModel) }
|
24
|
+
|
25
|
+
it { should contain "class Namespace::YourModelDecorator" }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "inheritance" do
|
29
|
+
context "by default" do
|
30
|
+
before { run_generator %w(YourModel) }
|
31
|
+
|
32
|
+
it { should contain "class YourModelDecorator < Draper::Decorator" }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with the --parent option" do
|
36
|
+
before { run_generator %w(YourModel --parent=FooDecorator) }
|
37
|
+
|
38
|
+
it { should contain "class YourModelDecorator < FooDecorator" }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with an ApplicationDecorator" do
|
42
|
+
before do
|
43
|
+
allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return(
|
44
|
+
stub_const "ApplicationDecorator", Class.new
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
before { run_generator %w(YourModel) }
|
49
|
+
|
50
|
+
it { should contain "class YourModelDecorator < ApplicationDecorator" }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with -t=rspec" do
|
56
|
+
describe "the generated spec" do
|
57
|
+
subject { file("spec/decorators/your_model_decorator_spec.rb") }
|
58
|
+
|
59
|
+
describe "naming" do
|
60
|
+
before { run_generator %w(YourModel -t=rspec) }
|
61
|
+
|
62
|
+
it { should contain "describe YourModelDecorator" }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "namespacing" do
|
66
|
+
subject { file("spec/decorators/namespace/your_model_decorator_spec.rb") }
|
67
|
+
before { run_generator %w(Namespace::YourModel -t=rspec) }
|
68
|
+
|
69
|
+
it { should contain "describe Namespace::YourModelDecorator" }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with -t=test_unit" do
|
75
|
+
describe "the generated test" do
|
76
|
+
subject { file("test/decorators/your_model_decorator_test.rb") }
|
77
|
+
|
78
|
+
describe "naming" do
|
79
|
+
before { run_generator %w(YourModel -t=test_unit) }
|
80
|
+
|
81
|
+
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "namespacing" do
|
85
|
+
subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
|
86
|
+
before { run_generator %w(Namespace::YourModel -t=test_unit) }
|
87
|
+
|
88
|
+
it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/dummy_app'
|
3
|
+
require 'support/matchers/have_text'
|
4
|
+
|
5
|
+
app = DummyApp.new(ENV["RAILS_ENV"])
|
6
|
+
spec_types = {
|
7
|
+
view: ["/posts/1", "PostsController"],
|
8
|
+
mailer: ["/posts/1/mail", "PostMailer"]
|
9
|
+
}
|
10
|
+
|
11
|
+
app.start_server do
|
12
|
+
spec_types.each do |type, (path, controller)|
|
13
|
+
page = app.get(path)
|
14
|
+
|
15
|
+
describe "in a #{type}" do
|
16
|
+
it "runs in the correct environment" do
|
17
|
+
expect(page).to have_text(app.environment).in("#environment")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "uses the correct view context controller" do
|
21
|
+
expect(page).to have_text(controller).in("#controller")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can use built-in helpers" do
|
25
|
+
expect(page).to have_text("Once upon a...").in("#truncated")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can use built-in private helpers" do
|
29
|
+
# Nokogiri unescapes text!
|
30
|
+
expect(page).to have_text("<script>danger</script>").in("#html_escaped")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can use user-defined helpers from app/helpers" do
|
34
|
+
expect(page).to have_text("Hello, world!").in("#hello_world")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can use user-defined helpers from the controller" do
|
38
|
+
expect(page).to have_text("Goodnight, moon!").in("#goodnight_moon")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can be passed to path helpers" do
|
42
|
+
expect(page).to have_text("/en/posts/1").in("#path_with_decorator")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can use path helpers with a model" do
|
46
|
+
expect(page).to have_text("/en/posts/1").in("#path_with_model")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can use path helpers with an id" do
|
50
|
+
expect(page).to have_text("/en/posts/1").in("#path_with_id")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can be passed to url helpers" do
|
54
|
+
expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_decorator")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can use url helpers with a model" do
|
58
|
+
expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_model")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can use url helpers with an id" do
|
62
|
+
expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_id")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|