strong_presenter 0.0.1 → 0.1.0
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 +7 -0
- data/.gitignore +5 -2
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +22 -2
- data/Guardfile +26 -0
- data/README.md +210 -52
- data/Rakefile +77 -1
- data/gemfiles/3.0.gemfile +2 -0
- data/gemfiles/3.1.gemfile +2 -0
- data/gemfiles/3.2.gemfile +2 -0
- data/gemfiles/4.0.gemfile +2 -0
- data/gemfiles/4.1.gemfile +2 -0
- data/lib/generators/controller_override.rb +15 -0
- data/lib/generators/mini_test/presenter_generator.rb +20 -0
- data/lib/generators/mini_test/templates/presenter_spec.rb +4 -0
- data/lib/generators/mini_test/templates/presenter_test.rb +4 -0
- data/lib/generators/rails/presenter_generator.rb +36 -0
- data/lib/generators/rails/templates/presenter.rb +19 -0
- data/lib/generators/rspec/presenter_generator.rb +9 -0
- data/lib/generators/rspec/templates/presenter_spec.rb +4 -0
- data/lib/generators/test_unit/presenter_generator.rb +9 -0
- data/lib/generators/test_unit/templates/presenter_test.rb +4 -0
- data/lib/strong_presenter/associable.rb +78 -0
- data/lib/strong_presenter/collection_presenter.rb +90 -0
- data/lib/strong_presenter/controller_additions.rb +50 -0
- data/lib/strong_presenter/delegation.rb +18 -0
- data/lib/strong_presenter/factory.rb +74 -0
- data/lib/strong_presenter/helper_proxy.rb +29 -11
- data/lib/strong_presenter/inferrer.rb +54 -0
- data/lib/strong_presenter/permissible.rb +73 -0
- data/lib/strong_presenter/permissions.rb +138 -0
- data/lib/strong_presenter/presenter.rb +191 -0
- data/lib/strong_presenter/presenter_association.rb +29 -0
- data/lib/strong_presenter/presenter_helper_constructor.rb +60 -0
- data/lib/strong_presenter/railtie.rb +27 -3
- data/lib/strong_presenter/tasks/test.rake +22 -0
- data/lib/strong_presenter/test/devise_helper.rb +30 -0
- data/lib/strong_presenter/test/minitest_integration.rb +6 -0
- data/lib/strong_presenter/test/rspec_integration.rb +16 -0
- data/lib/strong_presenter/test_case.rb +53 -0
- data/lib/strong_presenter/version.rb +1 -1
- data/lib/strong_presenter/view_context/build_strategy.rb +48 -0
- data/lib/strong_presenter/view_context.rb +84 -0
- data/lib/strong_presenter/view_helpers.rb +39 -0
- data/lib/strong_presenter.rb +64 -2
- 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 +25 -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/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/spec/dummy/app/presenters/post_presenter.rb +69 -0
- data/spec/dummy/app/presenters/special_post_presenter.rb +5 -0
- data/spec/dummy/app/presenters/special_posts_presenter.rb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +11 -0
- data/spec/dummy/app/views/post_mailer/presented_email.html.erb +1 -0
- data/spec/dummy/app/views/posts/_post.html.erb +50 -0
- data/spec/dummy/app/views/posts/show.html.erb +1 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/config/application.rb +70 -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/routes.rb +9 -0
- data/spec/dummy/config.ru +4 -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_presenter_spec.rb +37 -0
- data/spec/dummy/lib/tasks/test.rake +16 -0
- data/spec/dummy/log/.gitkeep +0 -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/fast_spec_helper.rb +13 -0
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +33 -0
- data/spec/dummy/spec/models/post_spec.rb +4 -0
- data/spec/dummy/spec/presenters/active_model_serializers_spec.rb +11 -0
- data/spec/dummy/spec/presenters/devise_spec.rb +64 -0
- data/spec/dummy/spec/presenters/helpers_spec.rb +21 -0
- data/spec/dummy/spec/presenters/post_presenter_spec.rb +66 -0
- data/spec/dummy/spec/presenters/spec_type_spec.rb +7 -0
- data/spec/dummy/spec/presenters/special_post_presenter_spec.rb +11 -0
- data/spec/dummy/spec/presenters/view_context_spec.rb +22 -0
- data/spec/dummy/spec/spec_helper.rb +19 -0
- data/spec/dummy/test/minitest_helper.rb +2 -0
- data/spec/dummy/test/presenters/minitest/devise_test.rb +64 -0
- data/spec/dummy/test/presenters/minitest/helpers_test.rb +21 -0
- data/spec/dummy/test/presenters/minitest/spec_type_test.rb +52 -0
- data/spec/dummy/test/presenters/minitest/view_context_test.rb +24 -0
- data/spec/dummy/test/presenters/test_unit/devise_test.rb +64 -0
- data/spec/dummy/test/presenters/test_unit/helpers_test.rb +21 -0
- data/spec/dummy/test/presenters/test_unit/view_context_test.rb +24 -0
- data/spec/dummy/test/test_helper.rb +13 -0
- data/spec/generators/presenters/presenter_generator_spec.rb +131 -0
- data/spec/generators/simplecov_spec.rb +5 -0
- data/spec/integration/integration_spec.rb +81 -0
- data/spec/integration/simplecov_spec.rb +4 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/strong_presenter/associable_spec.rb +122 -0
- data/spec/strong_presenter/collection_presenter_spec.rb +34 -0
- data/spec/strong_presenter/delegation_spec.rb +20 -0
- data/spec/strong_presenter/permissible_spec.rb +24 -0
- data/spec/strong_presenter/permissions_spec.rb +188 -0
- data/spec/strong_presenter/presenter_spec.rb +43 -0
- data/spec/strong_presenter/simplecov_spec.rb +4 -0
- data/spec/support/dummy_app.rb +85 -0
- data/spec/support/matchers/have_text.rb +50 -0
- data/spec/support/models.rb +14 -0
- data/spec/support/schema.rb +12 -0
- data/strong_presenter.gemspec +15 -0
- metadata +392 -13
- data/lib/strong_presenter/base.rb +0 -217
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Dummy::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
+
|
|
4
|
+
# The test environment is used exclusively to run your application's
|
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
|
8
|
+
config.cache_classes = true
|
|
9
|
+
|
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
|
11
|
+
# config.serve_static_assets = true
|
|
12
|
+
# config.static_cache_control = "public, max-age=3600"
|
|
13
|
+
|
|
14
|
+
# Show full error reports and disable caching
|
|
15
|
+
config.consider_all_requests_local = true
|
|
16
|
+
config.action_controller.perform_caching = false
|
|
17
|
+
|
|
18
|
+
# Raise exceptions instead of rendering exception templates
|
|
19
|
+
config.action_dispatch.show_exceptions = false
|
|
20
|
+
|
|
21
|
+
# Disable request forgery protection in test environment
|
|
22
|
+
config.action_controller.allow_forgery_protection = false
|
|
23
|
+
|
|
24
|
+
# Raise exception on mass assignment protection for Active Record models
|
|
25
|
+
# config.active_record.mass_assignment_sanitizer = :strict
|
|
26
|
+
|
|
27
|
+
# Print deprecation notices to the stderr
|
|
28
|
+
config.active_support.deprecation = :stderr
|
|
29
|
+
|
|
30
|
+
config.eager_load = false
|
|
31
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
|
5
|
+
|
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Add new inflection rules using the following format
|
|
4
|
+
# (all these examples are active by default):
|
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
|
8
|
+
# inflect.irregular 'person', 'people'
|
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
|
14
|
+
# inflect.acronym 'RESTful'
|
|
15
|
+
# end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
|
7
|
+
Dummy::Application.config.secret_key_base = 'c2e3474d3816f60bf6dd0f3b983e7283c7ff5373e11a96935340b544a31964dbe5ee077136165ee2975e0005f5e80207c0059e6d5589699031242ba5a06dcb87'
|
|
8
|
+
Dummy::Application.config.secret_token = 'c2e3474d3816f60bf6dd0f3b983e7283c7ff5373e11a96935340b544a31964dbe5ee077136165ee2975e0005f5e80207c0059e6d5589699031242ba5a06dcb87'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
|
4
|
+
|
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
|
6
|
+
# which shouldn't be used to store highly confidential information
|
|
7
|
+
# (create the session table with "rails generate session_migration")
|
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
|
@@ -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 'fast_spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'active_model/naming'
|
|
4
|
+
require_relative '../app/presenters/post_presenter'
|
|
5
|
+
|
|
6
|
+
StrongPresenter::ViewContext.test_strategy :fast
|
|
7
|
+
|
|
8
|
+
Post = Struct.new(:id) { extend ActiveModel::Naming }
|
|
9
|
+
|
|
10
|
+
describe PostPresenter do
|
|
11
|
+
let(:presenter) { PostPresenter.new(object) }
|
|
12
|
+
let(:object) { Post.new(42) }
|
|
13
|
+
|
|
14
|
+
it "can use built-in helpers" do
|
|
15
|
+
expect(presenter.truncated).to eq "Once upon a..."
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "can use built-in private helpers" do
|
|
19
|
+
expect(presenter.html_escaped).to eq "<script>danger</script>"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "can't use user-defined helpers from app/helpers" do
|
|
23
|
+
expect{presenter.hello_world}.to raise_error NoMethodError, /hello_world/
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "can't use path helpers" do
|
|
27
|
+
expect{presenter.path_with_model}.to raise_error NoMethodError, /post_path/
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "can't use url helpers" do
|
|
31
|
+
expect{presenter.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{presenter.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]
|
|
File without changes
|
|
@@ -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,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PostMailer do
|
|
4
|
+
describe "#presented_email" do
|
|
5
|
+
let(:email_body) { Capybara.string(email.body.to_s) }
|
|
6
|
+
let(:email) { PostMailer.presented_email(post).deliver }
|
|
7
|
+
let(:post) { Post.create }
|
|
8
|
+
|
|
9
|
+
it "presents" 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
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe StrongPresenter::CollectionPresenter do
|
|
4
|
+
describe "#active_model_serializer" do
|
|
5
|
+
it "returns ActiveModel::ArraySerializer" do
|
|
6
|
+
collection_presenter = StrongPresenter::CollectionPresenter.new([])
|
|
7
|
+
|
|
8
|
+
expect(collection_presenter.active_model_serializer).to be ActiveModel::ArraySerializer
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if defined?(Devise)
|
|
4
|
+
describe "A presenter 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 presenter 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 presenter" do
|
|
17
|
+
presenter = StrongPresenter::Presenter.new(Object.new)
|
|
18
|
+
|
|
19
|
+
expect(helpers).to be presenter.helpers
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PostPresenter do
|
|
4
|
+
let(:presenter) { PostPresenter.new(object) }
|
|
5
|
+
let(:object) { Post.create }
|
|
6
|
+
|
|
7
|
+
it "can use built-in helpers" do
|
|
8
|
+
expect(presenter.truncated).to eq "Once upon a..."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "can use built-in private helpers" do
|
|
12
|
+
expect(presenter.html_escaped).to eq "<script>danger</script>"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "can use user-defined helpers from app/helpers" do
|
|
16
|
+
expect(presenter.hello_world).to eq "Hello, world!"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "can be passed to path helpers" do
|
|
20
|
+
expect(helpers.post_path(presenter)).to eq "/en/posts/#{object.id}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "can use path helpers with its model" do
|
|
24
|
+
expect(presenter.path_with_model).to eq "/en/posts/#{object.id}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "can use path helpers with its id" do
|
|
28
|
+
expect(presenter.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(presenter)).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(presenter.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(presenter.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(presenter.link).to eq "<a href=\"/en/posts/#{object.id}\">#{object.id}</a>"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "serializes overriden attributes" do
|
|
48
|
+
expect(presenter.serializable_hash["updated_at"]).to be :overridden
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "serializes to JSON" do
|
|
52
|
+
json = presenter.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(presenter.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(StrongPresenter::ViewContext.current.controller).to be_an ApplicationController
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SpecialPostPresenter do
|
|
4
|
+
it 'has special collection' do
|
|
5
|
+
expect(SpecialPostPresenter::Collection).to be SpecialPostsPresenter
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'collection knows about presenter' do
|
|
9
|
+
expect(SpecialPostsPresenter.send(:presenter_class)).to be SpecialPostPresenter
|
|
10
|
+
end
|
|
11
|
+
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(StrongPresenter::ViewContext.current).not_to be :leaked
|
|
7
|
+
StrongPresenter::ViewContext.current = :leaked
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "A presenter spec", type: :presenter 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,19 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
root '../../'
|
|
5
|
+
command_name 'spec:integration:test:spec'
|
|
6
|
+
add_filter 'spec'
|
|
7
|
+
end
|
|
8
|
+
rescue LoadError
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
ENV['RAILS_ENV'] ||= 'test'
|
|
12
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
13
|
+
require 'rspec/rails'
|
|
14
|
+
|
|
15
|
+
RSpec.configure do |config|
|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
17
|
+
config.expect_with(:rspec) {|c| c.syntax = :expect}
|
|
18
|
+
config.order = :random
|
|
19
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'minitest_helper'
|
|
2
|
+
|
|
3
|
+
if defined?(Devise)
|
|
4
|
+
describe "A presenter 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 presenter 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 presenter" do
|
|
17
|
+
presenter = StrongPresenter::Presenter.new(Object.new)
|
|
18
|
+
|
|
19
|
+
assert_same presenter.helpers, helpers
|
|
20
|
+
end
|
|
21
|
+
end
|