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,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,37 @@
|
|
1
|
+
require 'draper'
|
2
|
+
|
3
|
+
require 'active_model/naming'
|
4
|
+
require_relative '../app/decorators/post_decorator'
|
5
|
+
|
6
|
+
Draper::ViewContext.test_strategy :fast
|
7
|
+
|
8
|
+
Post = Struct.new(:id) { extend ActiveModel::Naming }
|
9
|
+
|
10
|
+
describe PostDecorator do
|
11
|
+
let(:decorator) { PostDecorator.new(object) }
|
12
|
+
let(:object) { Post.new(42) }
|
13
|
+
|
14
|
+
it "can use built-in helpers" do
|
15
|
+
expect(decorator.truncated).to eq "Once upon a..."
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can use built-in private helpers" do
|
19
|
+
expect(decorator.html_escaped).to eq "<script>danger</script>"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can't use user-defined helpers from app/helpers" do
|
23
|
+
expect{decorator.hello_world}.to raise_error NoMethodError, /hello_world/
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can't use path helpers" do
|
27
|
+
expect{decorator.path_with_model}.to raise_error NoMethodError, /post_path/
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can't use url helpers" do
|
31
|
+
expect{decorator.url_with_model}.to raise_error NoMethodError, /post_url/
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can't be passed implicitly to url_for" do
|
35
|
+
expect{decorator.link}.to raise_error
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
Rake::Task[:test].clear
|
5
|
+
Rake::TestTask.new :test do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
t.pattern = "test/**/*_test.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new :spec
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new :fast_spec do |t|
|
13
|
+
t.pattern = "fast_spec/**/*_spec.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => [:test, :spec, :fast_spec]
|
@@ -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,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Draper::CollectionDecorator do
|
4
|
+
describe "#active_model_serializer" do
|
5
|
+
it "returns ActiveModel::ArraySerializer" do
|
6
|
+
collection_decorator = Draper::CollectionDecorator.new([])
|
7
|
+
if defined?(ActiveModel::ArraySerializerSupport)
|
8
|
+
collection_serializer = collection_decorator.active_model_serializer
|
9
|
+
else
|
10
|
+
collection_serializer = ActiveModel::Serializer.serializer_for(collection_decorator)
|
11
|
+
end
|
12
|
+
|
13
|
+
expect(collection_serializer).to be ActiveModel::ArraySerializer
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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
|
+
|
55
|
+
it "is backwards-compatible" do
|
56
|
+
user = double("User")
|
57
|
+
ActiveSupport::Deprecation.silence do
|
58
|
+
sign_in user
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(helper.current_user).to be user
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,66 @@
|
|
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
|
+
pending("Rails < 3.2 does not use `serializable_hash` in `to_xml`") if Rails.version.to_f < 3.2
|
58
|
+
|
59
|
+
xml = Capybara.string(decorator.to_xml)
|
60
|
+
expect(xml).to have_css "post > updated-at", text: "overridden"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "uses a test view context from ApplicationController" do
|
64
|
+
expect(Draper::ViewContext.current.controller).to be_an ApplicationController
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
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 path helpers with a model" do
|
14
|
+
expect(email_body).to have_css "#path_with_model", text: "/en/posts/#{post.id}"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can use path helpers with an id" do
|
18
|
+
expect(email_body).to have_css "#path_with_id", text: "/en/posts/#{post.id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can use url helpers with a model" do
|
22
|
+
expect(email_body).to have_css "#url_with_model", text: "http://www.example.com:12345/en/posts/#{post.id}"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can use url helpers with an id" do
|
26
|
+
expect(email_body).to have_css "#url_with_id", text: "http://www.example.com:12345/en/posts/#{post.id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "uses the correct view context controller" do
|
30
|
+
expect(email_body).to have_css "#controller", text: "PostMailer"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|