draper 4.0.4 → 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/CHANGELOG.md +6 -0
- data/README.md +3 -6
- 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.rb +5 -0
- data/lib/draper/decorator.rb +2 -18
- data/lib/draper/railtie.rb +6 -1
- data/lib/draper/version.rb +1 -1
- metadata +4 -232
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -24
- data/.github/workflows/ci.yml +0 -71
- data/.gitignore +0 -18
- data/Gemfile +0 -46
- 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 -80
- 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 -115
- data/spec/draper/view_context_spec.rb +0 -182
- data/spec/draper/view_helpers_spec.rb +0 -8
- data/spec/dummy/.rspec +0 -1
- 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/comment_decorator.rb +0 -13
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +0 -2
- 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 -3
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/comment.rb +0 -3
- data/spec/dummy/app/models/mongoid_post.rb +0 -3
- data/spec/dummy/app/models/post.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -3
- 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 -39
- 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 -78
- data/spec/dummy/config/environments/production.rb +0 -102
- data/spec/dummy/config/environments/test.rb +0 -69
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/draper.rb +0 -5
- 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/migrate/20240907041839_create_comments.rb +0 -9
- data/spec/dummy/db/schema.rb +0 -28
- 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 -11
- 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 -51
- data/spec/dummy/spec/rails_helper.rb +0 -69
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -22
- data/spec/dummy/spec/spec_helper.rb +0 -93
- 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
data/spec/dummy/public/500.html
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
data/spec/dummy/script/rails
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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'
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require 'rails_helper'
|
|
2
|
-
|
|
3
|
-
describe Draper::CollectionDecorator do
|
|
4
|
-
describe "#active_model_serializer" do
|
|
5
|
-
it "returns ActiveModel::Serializer::CollectionSerializer" do
|
|
6
|
-
collection_decorator = Draper::CollectionDecorator.new([])
|
|
7
|
-
collection_serializer = ActiveModel::Serializer.serializer_for(collection_decorator)
|
|
8
|
-
|
|
9
|
-
expect(collection_serializer).to be ActiveModel::Serializer::CollectionSerializer
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
if defined?(Devise)
|
|
4
|
-
describe "A decorator spec" do
|
|
5
|
-
it "can sign in a real user" do
|
|
6
|
-
user = User.new
|
|
7
|
-
sign_in user
|
|
8
|
-
|
|
9
|
-
expect(helper.current_user).to be user
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "can sign in a mock user" do
|
|
13
|
-
user = double("User")
|
|
14
|
-
sign_in :user, user
|
|
15
|
-
|
|
16
|
-
expect(helper.current_user).to be user
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "can sign in a real admin" do
|
|
20
|
-
admin = Admin.new
|
|
21
|
-
sign_in admin
|
|
22
|
-
|
|
23
|
-
expect(helper.current_admin).to be admin
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "can sign in a mock admin" do
|
|
27
|
-
admin = double("Admin")
|
|
28
|
-
sign_in :admin, admin
|
|
29
|
-
|
|
30
|
-
expect(helper.current_admin).to be 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
|
-
expect(helper.current_user).to be_nil
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "can sign out a mock user" do
|
|
42
|
-
user = double("User")
|
|
43
|
-
sign_in :user, user
|
|
44
|
-
sign_out :user
|
|
45
|
-
|
|
46
|
-
expect(helper.current_user).to be_nil
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "can sign out without a user" do
|
|
50
|
-
sign_out :user
|
|
51
|
-
|
|
52
|
-
expect(helper.current_user).to be_nil
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -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 'rails_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,11 +0,0 @@
|
|
|
1
|
-
require 'rails_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe PublishPostJob, type: :job do
|
|
4
|
-
let(:post) { Post.create.decorate }
|
|
5
|
-
|
|
6
|
-
subject(:job) { described_class.perform_later(post) }
|
|
7
|
-
|
|
8
|
-
it 'queues the job' do
|
|
9
|
-
expect { job }.to have_enqueued_job(described_class).with(post.object)
|
|
10
|
-
end
|
|
11
|
-
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,51 +0,0 @@
|
|
|
1
|
-
require 'rails_helper'
|
|
2
|
-
require 'shared_examples/decoratable'
|
|
3
|
-
|
|
4
|
-
RSpec.describe Post do
|
|
5
|
-
let(:record) { described_class.create! }
|
|
6
|
-
|
|
7
|
-
it_behaves_like 'a decoratable model'
|
|
8
|
-
|
|
9
|
-
it { should be_a ApplicationRecord }
|
|
10
|
-
|
|
11
|
-
describe 'associations' do
|
|
12
|
-
context 'when decorated' do
|
|
13
|
-
subject { associated.decorate }
|
|
14
|
-
|
|
15
|
-
let(:associated) { record.comments }
|
|
16
|
-
let(:persisted) { associated.create! [{}] * rand(0..2) }
|
|
17
|
-
let(:unsaved) { associated.build [{}] * rand(1..2) }
|
|
18
|
-
|
|
19
|
-
before { persisted } # should exist
|
|
20
|
-
|
|
21
|
-
it 'returns a decorated collection' do
|
|
22
|
-
is_expected.to match_array persisted
|
|
23
|
-
is_expected.to be_all &:decorated?
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'uses cached records' do
|
|
27
|
-
expect(associated).not_to be_loaded
|
|
28
|
-
|
|
29
|
-
associated.load
|
|
30
|
-
|
|
31
|
-
expect { subject.to_a }.to execute.exactly(0).queries
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'caches records' do
|
|
35
|
-
expect(associated).not_to be_loaded
|
|
36
|
-
|
|
37
|
-
associated.decorate
|
|
38
|
-
|
|
39
|
-
expect { subject.to_a; associated.load }.to execute.exactly(0).queries
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'with unsaved records' do
|
|
43
|
-
before { unsaved } # should exist
|
|
44
|
-
|
|
45
|
-
it 'respects unsaved records' do
|
|
46
|
-
is_expected.to match_array persisted + unsaved
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
ENV['RAILS_ENV'] ||= 'test'
|
|
4
|
-
require_relative '../config/environment'
|
|
5
|
-
# Prevent database truncation if the environment is production
|
|
6
|
-
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
|
7
|
-
require 'rspec/rails'
|
|
8
|
-
require 'rspec/activerecord/expectations'
|
|
9
|
-
# Add additional requires below this line. Rails is not loaded until this point!
|
|
10
|
-
|
|
11
|
-
# Requires supporting ruby files with custom matchers and macros, etc, in
|
|
12
|
-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
|
13
|
-
# run as spec files by default. This means that files in spec/support that end
|
|
14
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
|
15
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
|
16
|
-
# end with _spec.rb. You can configure this pattern with the --pattern
|
|
17
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
|
18
|
-
#
|
|
19
|
-
# The following line is provided for convenience purposes. It has the downside
|
|
20
|
-
# of increasing the boot-up time by auto-requiring all files in the support
|
|
21
|
-
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
|
22
|
-
# require only the support files necessary.
|
|
23
|
-
#
|
|
24
|
-
# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }
|
|
25
|
-
|
|
26
|
-
# Checks for pending migrations and applies them before tests are run.
|
|
27
|
-
# If you are not using ActiveRecord, you can remove these lines.
|
|
28
|
-
begin
|
|
29
|
-
ActiveRecord::Migration.maintain_test_schema!
|
|
30
|
-
rescue ActiveRecord::PendingMigrationError => e
|
|
31
|
-
abort e.to_s.strip
|
|
32
|
-
end
|
|
33
|
-
RSpec.configure do |config|
|
|
34
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
|
35
|
-
# config.fixture_paths = [
|
|
36
|
-
# Rails.root.join('spec/fixtures')
|
|
37
|
-
# ]
|
|
38
|
-
|
|
39
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
40
|
-
# examples within a transaction, remove the following line or assign false
|
|
41
|
-
# instead of true.
|
|
42
|
-
# config.use_transactional_fixtures = true
|
|
43
|
-
|
|
44
|
-
# You can uncomment this line to turn off ActiveRecord support entirely.
|
|
45
|
-
# config.use_active_record = false
|
|
46
|
-
|
|
47
|
-
# RSpec Rails can automatically mix in different behaviours to your tests
|
|
48
|
-
# based on their file location, for example enabling you to call `get` and
|
|
49
|
-
# `post` in specs under `spec/controllers`.
|
|
50
|
-
#
|
|
51
|
-
# You can disable this behaviour by removing the line below, and instead
|
|
52
|
-
# explicitly tag your specs with their type, e.g.:
|
|
53
|
-
#
|
|
54
|
-
# RSpec.describe UsersController, type: :controller do
|
|
55
|
-
# # ...
|
|
56
|
-
# end
|
|
57
|
-
#
|
|
58
|
-
# The different available types are documented in the features, such as in
|
|
59
|
-
# https://rspec.info/features/6-0/rspec-rails
|
|
60
|
-
config.infer_spec_type_from_file_location!
|
|
61
|
-
|
|
62
|
-
# Filter lines from Rails gems in backtraces.
|
|
63
|
-
config.filter_rails_from_backtrace!
|
|
64
|
-
# arbitrary gems may also be filtered via:
|
|
65
|
-
# config.filter_gems_from_backtrace("gem name")
|
|
66
|
-
|
|
67
|
-
# Extra matchers
|
|
68
|
-
config.include RSpec::ActiveRecord::Expectations
|
|
69
|
-
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,93 +0,0 @@
|
|
|
1
|
-
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
3
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
4
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
|
5
|
-
# files.
|
|
6
|
-
#
|
|
7
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
|
8
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
9
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
10
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
|
11
|
-
# a separate helper file that requires the additional dependencies and performs
|
|
12
|
-
# the additional setup, and require it from the spec files that actually need
|
|
13
|
-
# it.
|
|
14
|
-
#
|
|
15
|
-
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
16
|
-
RSpec.configure do |config|
|
|
17
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
18
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
19
|
-
# assertions if you prefer.
|
|
20
|
-
config.expect_with :rspec do |expectations|
|
|
21
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
22
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
23
|
-
# defined using `chain`, e.g.:
|
|
24
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
25
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
26
|
-
# ...rather than:
|
|
27
|
-
# # => "be bigger than 2"
|
|
28
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
32
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
33
|
-
config.mock_with :rspec do |mocks|
|
|
34
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
35
|
-
# a real object. This is generally recommended, and will default to
|
|
36
|
-
# `true` in RSpec 4.
|
|
37
|
-
mocks.verify_partial_doubles = true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
41
|
-
# have no way to turn it off -- the option exists only for backwards
|
|
42
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
43
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
|
44
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
45
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
46
|
-
|
|
47
|
-
# The settings below are suggested to provide a good initial experience
|
|
48
|
-
# with RSpec, but feel free to customize to your heart's content.
|
|
49
|
-
|
|
50
|
-
# This allows you to limit a spec run to individual examples or groups
|
|
51
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
|
52
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
|
53
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
|
54
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
55
|
-
config.filter_run_when_matching :focus
|
|
56
|
-
|
|
57
|
-
# Allows RSpec to persist some state between runs in order to support
|
|
58
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
59
|
-
# you configure your source control system to ignore this file.
|
|
60
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
61
|
-
|
|
62
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
|
63
|
-
# recommended. For more details, see:
|
|
64
|
-
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
|
|
65
|
-
# config.disable_monkey_patching!
|
|
66
|
-
|
|
67
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
|
68
|
-
# file, and it's useful to allow more verbose output when running an
|
|
69
|
-
# individual spec file.
|
|
70
|
-
if config.files_to_run.one?
|
|
71
|
-
# Use the documentation formatter for detailed output,
|
|
72
|
-
# unless a formatter has already been configured
|
|
73
|
-
# (e.g. via a command-line flag).
|
|
74
|
-
config.default_formatter = "doc"
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Print the 10 slowest examples and example groups at the
|
|
78
|
-
# end of the spec run, to help surface which specs are running
|
|
79
|
-
# particularly slow.
|
|
80
|
-
config.profile_examples = 10
|
|
81
|
-
|
|
82
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
83
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
84
|
-
# the seed, which is printed after each run.
|
|
85
|
-
# --seed 1234
|
|
86
|
-
config.order = :random
|
|
87
|
-
|
|
88
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
89
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
90
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
91
|
-
# as the one that triggered the failure.
|
|
92
|
-
Kernel.srand config.seed
|
|
93
|
-
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
|