draper 4.0.2 → 4.0.5
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.
- checksums.yaml +4 -4
- data/.rspec +1 -2
- data/CHANGELOG.md +24 -0
- data/README.md +26 -7
- data/lib/draper/automatic_delegation.rb +14 -4
- data/lib/draper/collection_decorator.rb +0 -6
- data/lib/draper/compatibility/broadcastable.rb +24 -0
- data/lib/draper/compatibility/global_id.rb +9 -5
- data/lib/draper/decoratable/collection_proxy.rb +15 -0
- data/lib/draper/decoratable.rb +7 -2
- data/lib/draper/decorator.rb +2 -18
- data/lib/draper/query_methods.rb +1 -1
- data/lib/draper/railtie.rb +14 -5
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context/build_strategy.rb +1 -9
- data/lib/draper.rb +0 -6
- metadata +16 -235
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -24
- data/.github/workflows/ci.yml +0 -55
- data/.gitignore +0 -18
- data/Gemfile +0 -24
- data/bin/bundle +0 -114
- data/bin/rake +0 -29
- data/draper.gemspec +0 -34
- data/spec/draper/collection_decorator_spec.rb +0 -291
- data/spec/draper/configuration_spec.rb +0 -49
- data/spec/draper/decoratable/equality_spec.rb +0 -10
- data/spec/draper/decoratable_spec.rb +0 -235
- data/spec/draper/decorated_association_spec.rb +0 -82
- data/spec/draper/decorates_assigned_spec.rb +0 -71
- data/spec/draper/decorator_spec.rb +0 -872
- data/spec/draper/draper_spec.rb +0 -25
- data/spec/draper/factory_spec.rb +0 -247
- data/spec/draper/finders_spec.rb +0 -166
- data/spec/draper/helper_proxy_spec.rb +0 -61
- data/spec/draper/lazy_helpers_spec.rb +0 -21
- data/spec/draper/query_methods/load_strategy_spec.rb +0 -26
- data/spec/draper/query_methods_spec.rb +0 -70
- data/spec/draper/undecorate_chain_spec.rb +0 -20
- data/spec/draper/undecorate_spec.rb +0 -19
- data/spec/draper/view_context/build_strategy_spec.rb +0 -132
- data/spec/draper/view_context_spec.rb +0 -182
- data/spec/draper/view_helpers_spec.rb +0 -8
- data/spec/dummy/.rspec +0 -2
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/base_controller.rb +0 -4
- data/spec/dummy/app/controllers/localized_urls.rb +0 -5
- data/spec/dummy/app/controllers/posts_controller.rb +0 -20
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +0 -4
- data/spec/dummy/app/decorators/post_decorator.rb +0 -60
- data/spec/dummy/app/helpers/application_helper.rb +0 -5
- data/spec/dummy/app/jobs/publish_post_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -3
- data/spec/dummy/app/mailers/post_mailer.rb +0 -19
- data/spec/dummy/app/models/admin.rb +0 -5
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/mongoid_post.rb +0 -5
- data/spec/dummy/app/models/post.rb +0 -3
- data/spec/dummy/app/models/user.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -11
- data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +0 -1
- data/spec/dummy/app/views/posts/_post.html.erb +0 -42
- data/spec/dummy/app/views/posts/show.html.erb +0 -1
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/config/application.rb +0 -68
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -35
- data/spec/dummy/config/environments/production.rb +0 -59
- data/spec/dummy/config/environments/test.rb +0 -35
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/draper.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -8
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/mongoid.yml +0 -142
- data/spec/dummy/config/routes.rb +0 -9
- data/spec/dummy/config/storage.yml +0 -7
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +0 -8
- data/spec/dummy/db/schema.rb +0 -21
- data/spec/dummy/db/seeds.rb +0 -2
- data/spec/dummy/fast_spec/post_decorator_spec.rb +0 -37
- data/spec/dummy/lib/tasks/test.rake +0 -16
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +0 -12
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -55
- data/spec/dummy/spec/decorators/helpers_spec.rb +0 -21
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +0 -64
- data/spec/dummy/spec/decorators/spec_type_spec.rb +0 -7
- data/spec/dummy/spec/decorators/view_context_spec.rb +0 -22
- data/spec/dummy/spec/jobs/publish_post_job_spec.rb +0 -9
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +0 -25
- data/spec/dummy/spec/models/application_spec.rb +0 -7
- data/spec/dummy/spec/models/mongoid_post_spec.rb +0 -8
- data/spec/dummy/spec/models/post_spec.rb +0 -15
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -22
- data/spec/dummy/spec/spec_helper.rb +0 -8
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/minitest/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/minitest/spec_type_test.rb +0 -52
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +0 -24
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/test_unit/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +0 -24
- data/spec/dummy/test/minitest_helper.rb +0 -2
- data/spec/dummy/test/test_helper.rb +0 -3
- data/spec/generators/controller/controller_generator_spec.rb +0 -23
- data/spec/generators/decorator/decorator_generator_spec.rb +0 -93
- data/spec/generators/install/install_generator_spec.rb +0 -19
- data/spec/integration/integration_spec.rb +0 -70
- data/spec/performance/active_record.rb +0 -4
- data/spec/performance/benchmark.rb +0 -55
- data/spec/performance/decorators.rb +0 -45
- data/spec/performance/models.rb +0 -20
- data/spec/spec_helper.rb +0 -50
- data/spec/support/dummy_app.rb +0 -85
- data/spec/support/matchers/have_text.rb +0 -50
- data/spec/support/shared_examples/decoratable_equality.rb +0 -40
- data/spec/support/shared_examples/view_helpers.rb +0 -39
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe "A decorator spec" do
|
|
4
|
-
it "can access helpers through `helper`" do
|
|
5
|
-
expect(helper.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "can access helpers through `helpers`" do
|
|
9
|
-
expect(helpers.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "can access helpers through `h`" do
|
|
13
|
-
expect(h.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "gets the same helper object as a decorator" do
|
|
17
|
-
decorator = Draper::Decorator.new(Object.new)
|
|
18
|
-
|
|
19
|
-
expect(helpers).to be decorator.helpers
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe PostDecorator do
|
|
4
|
-
let(:decorator) { PostDecorator.new(object) }
|
|
5
|
-
let(:object) { Post.create }
|
|
6
|
-
|
|
7
|
-
it "can use built-in helpers" do
|
|
8
|
-
expect(decorator.truncated).to eq "Once upon a..."
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "can use built-in private helpers" do
|
|
12
|
-
expect(decorator.html_escaped).to eq "<script>danger</script>"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "can use user-defined helpers from app/helpers" do
|
|
16
|
-
expect(decorator.hello_world).to eq "Hello, world!"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "can be passed to path helpers" do
|
|
20
|
-
expect(helpers.post_path(decorator)).to eq "/en/posts/#{object.id}"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "can use path helpers with its model" do
|
|
24
|
-
expect(decorator.path_with_model).to eq "/en/posts/#{object.id}"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "can use path helpers with its id" do
|
|
28
|
-
expect(decorator.path_with_id).to eq "/en/posts/#{object.id}"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "can be passed to url helpers" do
|
|
32
|
-
expect(helpers.post_url(decorator)).to eq "http://www.example.com:12345/en/posts/#{object.id}"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "can use url helpers with its model" do
|
|
36
|
-
expect(decorator.url_with_model).to eq "http://www.example.com:12345/en/posts/#{object.id}"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "can use url helpers with its id" do
|
|
40
|
-
expect(decorator.url_with_id).to eq "http://www.example.com:12345/en/posts/#{object.id}"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "can be passed implicitly to url_for" do
|
|
44
|
-
expect(decorator.link).to eq "<a href=\"/en/posts/#{object.id}\">#{object.id}</a>"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "serializes overriden attributes" do
|
|
48
|
-
expect(decorator.serializable_hash["updated_at"]).to be :overridden
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "serializes to JSON" do
|
|
52
|
-
json = decorator.to_json
|
|
53
|
-
expect(json).to match /"updated_at":"overridden"/
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "serializes to XML" do
|
|
57
|
-
xml = Capybara.string(decorator.to_xml)
|
|
58
|
-
expect(xml).to have_css "post > updated-at", text: "overridden"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "uses a test view context from BaseController" do
|
|
62
|
-
expect(Draper::ViewContext.current.controller).to be_an BaseController
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
def it_does_not_leak_view_context
|
|
4
|
-
2.times do
|
|
5
|
-
it "has an independent view context" do
|
|
6
|
-
expect(Draper::ViewContext.current).not_to be :leaked
|
|
7
|
-
Draper::ViewContext.current = :leaked
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "A decorator spec", type: :decorator do
|
|
13
|
-
it_does_not_leak_view_context
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "A controller spec", type: :controller do
|
|
17
|
-
it_does_not_leak_view_context
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "A mailer spec", type: :mailer do
|
|
21
|
-
it_does_not_leak_view_context
|
|
22
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe PostMailer do
|
|
4
|
-
describe "#decorated_email" do
|
|
5
|
-
let(:email_body) { 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
|
-
expect(email_body).to have_content "Today"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "can use url helpers with a model" do
|
|
14
|
-
expect(email_body).to have_css "#url_with_model", text: "http://www.example.com:12345/en/posts/#{post.id}"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "can use url helpers with an id" do
|
|
18
|
-
expect(email_body).to have_css "#url_with_id", text: "http://www.example.com:12345/en/posts/#{post.id}"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "uses the correct view context controller" do
|
|
22
|
-
expect(email_body).to have_css "#controller", text: "PostMailer"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'shared_examples/decoratable'
|
|
3
|
-
|
|
4
|
-
RSpec.describe Post do
|
|
5
|
-
it_behaves_like 'a decoratable model'
|
|
6
|
-
|
|
7
|
-
it { should be_a ApplicationRecord }
|
|
8
|
-
|
|
9
|
-
describe '#to_global_id' do
|
|
10
|
-
let(:post) { Post.create }
|
|
11
|
-
subject { post.to_global_id }
|
|
12
|
-
|
|
13
|
-
it { is_expected.to eq post.decorate.to_global_id }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
described_class.create
|
|
15
|
-
one = described_class.first
|
|
16
|
-
other = described_class.first
|
|
17
|
-
|
|
18
|
-
expect(one).not_to be other
|
|
19
|
-
expect(one == other.decorate).to be_truthy
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
end
|
|
55
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
|
@@ -1,24 +0,0 @@
|
|
|
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 decorator test" do
|
|
17
|
-
subject { Class.new(ActionController::Base) }
|
|
18
|
-
|
|
19
|
-
it_does_not_leak_view_context
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "A mailer decorator test" do
|
|
23
|
-
it_does_not_leak_view_context
|
|
24
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
end
|
|
55
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
subject{ 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
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'dummy/config/environment'
|
|
3
|
-
require 'ammeter/init'
|
|
4
|
-
require 'generators/controller_override'
|
|
5
|
-
require 'generators/rails/decorator_generator'
|
|
6
|
-
SimpleCov.command_name 'test:generator'
|
|
7
|
-
|
|
8
|
-
describe Rails::Generators::ControllerGenerator do
|
|
9
|
-
destination File.expand_path("../tmp", __FILE__)
|
|
10
|
-
|
|
11
|
-
before { prepare_destination }
|
|
12
|
-
after(:all) { FileUtils.rm_rf destination_root }
|
|
13
|
-
|
|
14
|
-
describe "the generated decorator" do
|
|
15
|
-
subject { file("app/decorators/your_model_decorator.rb") }
|
|
16
|
-
|
|
17
|
-
describe "naming" do
|
|
18
|
-
before { run_generator %w(YourModels) }
|
|
19
|
-
|
|
20
|
-
it { is_expected.to contain "class YourModelDecorator" }
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'dummy/config/environment'
|
|
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 { is_expected.to 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 { is_expected.to 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 { is_expected.to 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 { is_expected.to 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).and_call_original
|
|
44
|
-
allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return(
|
|
45
|
-
stub_const "ApplicationDecorator", Class.new
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
before { run_generator %w(YourModel) }
|
|
50
|
-
|
|
51
|
-
it { is_expected.to contain "class YourModelDecorator < ApplicationDecorator" }
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context "with -t=rspec" do
|
|
57
|
-
describe "the generated spec" do
|
|
58
|
-
subject { file("spec/decorators/your_model_decorator_spec.rb") }
|
|
59
|
-
|
|
60
|
-
describe "naming" do
|
|
61
|
-
before { run_generator %w(YourModel -t=rspec) }
|
|
62
|
-
|
|
63
|
-
it { is_expected.to contain "describe YourModelDecorator" }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe "namespacing" do
|
|
67
|
-
subject { file("spec/decorators/namespace/your_model_decorator_spec.rb") }
|
|
68
|
-
before { run_generator %w(Namespace::YourModel -t=rspec) }
|
|
69
|
-
|
|
70
|
-
it { is_expected.to contain "describe Namespace::YourModelDecorator" }
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "with -t=test_unit" do
|
|
76
|
-
describe "the generated test" do
|
|
77
|
-
subject { file("test/decorators/your_model_decorator_test.rb") }
|
|
78
|
-
|
|
79
|
-
describe "naming" do
|
|
80
|
-
before { run_generator %w(YourModel -t=test_unit) }
|
|
81
|
-
|
|
82
|
-
it { is_expected.to contain "class YourModelDecoratorTest < Draper::TestCase" }
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe "namespacing" do
|
|
86
|
-
subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
|
|
87
|
-
before { run_generator %w(Namespace::YourModel -t=test_unit) }
|
|
88
|
-
|
|
89
|
-
it { is_expected.to contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'dummy/config/environment'
|
|
3
|
-
require 'ammeter/init'
|
|
4
|
-
require 'generators/draper/install_generator'
|
|
5
|
-
|
|
6
|
-
describe Draper::Generators::InstallGenerator 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 application decorator' do
|
|
13
|
-
subject { file('app/decorators/application_decorator.rb') }
|
|
14
|
-
|
|
15
|
-
before { run_generator }
|
|
16
|
-
|
|
17
|
-
it { is_expected.to contain 'class ApplicationDecorator' }
|
|
18
|
-
end
|
|
19
|
-
end
|