parent
cfd36b45f8
commit
cfbc3888e9
|
@ -1,13 +0,0 @@
|
||||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
||||||
// listed below.
|
|
||||||
//
|
|
||||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
||||||
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
||||||
//
|
|
||||||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
||||||
// the compiled file.
|
|
||||||
//
|
|
||||||
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
|
||||||
// GO AFTER THE REQUIRES BELOW.
|
|
||||||
//
|
|
||||||
//= require_tree .
|
|
|
@ -1,13 +0,0 @@
|
||||||
/*
|
|
||||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
||||||
* listed below.
|
|
||||||
*
|
|
||||||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
||||||
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
||||||
*
|
|
||||||
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
|
||||||
* compiled file, but it's generally better to create a new file per style scope.
|
|
||||||
*
|
|
||||||
*= require_self
|
|
||||||
*= require_tree .
|
|
||||||
*/
|
|
|
@ -1,7 +1,4 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
include LocalizedUrls
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
def default_url_options(options = {})
|
|
||||||
{locale: I18n.locale, host: "www.example.com", port: nil}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
module LocalizedUrls
|
||||||
|
def default_url_options(options = {})
|
||||||
|
{locale: I18n.locale, host: "www.example.com", port: nil}
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,17 @@
|
||||||
class PostsController < ApplicationController
|
class PostsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
|
fetch_post
|
||||||
|
end
|
||||||
|
|
||||||
|
def mail
|
||||||
|
fetch_post
|
||||||
|
email = PostMailer.decorated_email(@post).deliver
|
||||||
|
render text: email.body
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def fetch_post
|
||||||
@post = Post.find(params[:id]).decorate
|
@post = Post.find(params[:id]).decorate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
class ApplicationMailer < ActionMailer::Base
|
||||||
|
include LocalizedUrls
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class PostMailer < ApplicationMailer
|
||||||
|
default from: "from@example.com"
|
||||||
|
layout "application"
|
||||||
|
|
||||||
|
def decorated_email(post)
|
||||||
|
@post = post.decorate
|
||||||
|
mail to: "to@example.com", subject: "A decorated post"
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,9 +2,6 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Dummy</title>
|
<title>Dummy</title>
|
||||||
<%= stylesheet_link_tag "application", :media => "all" %>
|
|
||||||
<%= javascript_include_tag "application" %>
|
|
||||||
<%= csrf_meta_tags %>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<%= render @post %>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<dl>
|
||||||
|
<dt>Environment:</dt>
|
||||||
|
<dd id="environment"><%= Rails.env %></dd>
|
||||||
|
|
||||||
|
<dt>Posted:</dt>
|
||||||
|
<dd id="posted_date"><%= post.posted_date %></dd>
|
||||||
|
|
||||||
|
<dt>Path with model:</dt>
|
||||||
|
<dd id="path_with_model"><%= post.path_with_model %></dd>
|
||||||
|
|
||||||
|
<dt>Path with id:</dt>
|
||||||
|
<dd id="path_with_id"><%= post.path_with_id %></dd>
|
||||||
|
|
||||||
|
<dt>URL with model:</dt>
|
||||||
|
<dd id="url_with_model"><%= post.url_with_model %></dd>
|
||||||
|
|
||||||
|
<dt>URL with id:</dt>
|
||||||
|
<dd id="url_with_id"><%= post.url_with_id %></dd>
|
||||||
|
</dl>
|
|
@ -1,19 +1 @@
|
||||||
<dl>
|
<%= render @post %>
|
||||||
<dt>Environment:</dt>
|
|
||||||
<dd id="environment"><%= Rails.env %></dd>
|
|
||||||
|
|
||||||
<dt>Posted:</dt>
|
|
||||||
<dd id="posted_date"><%= @post.posted_date %></dd>
|
|
||||||
|
|
||||||
<dt>Path with model:</dt>
|
|
||||||
<dd id="path_with_model"><%= @post.path_with_model %></dd>
|
|
||||||
|
|
||||||
<dt>Path with id:</dt>
|
|
||||||
<dd id="path_with_id"><%= @post.path_with_id %></dd>
|
|
||||||
|
|
||||||
<dt>URL with model:</dt>
|
|
||||||
<dd id="url_with_model"><%= @post.url_with_model %></dd>
|
|
||||||
|
|
||||||
<dt>URL with id:</dt>
|
|
||||||
<dd id="url_with_id"><%= @post.url_with_id %></dd>
|
|
||||||
</dl>
|
|
||||||
|
|
|
@ -54,6 +54,11 @@ module Dummy
|
||||||
|
|
||||||
# Version of your assets, change this if you want to expire all your assets
|
# Version of your assets, change this if you want to expire all your assets
|
||||||
config.assets.version = '1.0'
|
config.assets.version = '1.0'
|
||||||
|
|
||||||
|
# Tell Action Mailer not to deliver emails to the real world.
|
||||||
|
# The :test delivery method accumulates sent emails in the
|
||||||
|
# ActionMailer::Base.deliveries array.
|
||||||
|
config.action_mailer.delivery_method = :test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,6 @@ Dummy::Application.configure do
|
||||||
config.consider_all_requests_local = true
|
config.consider_all_requests_local = true
|
||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
# Don't care if the mailer can't send
|
|
||||||
config.action_mailer.raise_delivery_errors = false
|
|
||||||
|
|
||||||
# Print deprecation notices to the Rails logger
|
# Print deprecation notices to the Rails logger
|
||||||
config.active_support.deprecation = :log
|
config.active_support.deprecation = :log
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,6 @@ Dummy::Application.configure do
|
||||||
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
||||||
# config.assets.precompile += %w( search.js )
|
# config.assets.precompile += %w( search.js )
|
||||||
|
|
||||||
# Disable delivery errors, bad email addresses will be ignored
|
|
||||||
# config.action_mailer.raise_delivery_errors = false
|
|
||||||
|
|
||||||
# Enable threaded mode
|
# Enable threaded mode
|
||||||
# config.threadsafe!
|
# config.threadsafe!
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,6 @@ Dummy::Application.configure do
|
||||||
# Disable request forgery protection in test environment
|
# Disable request forgery protection in test environment
|
||||||
config.action_controller.allow_forgery_protection = false
|
config.action_controller.allow_forgery_protection = false
|
||||||
|
|
||||||
# Tell Action Mailer not to deliver emails to the real world.
|
|
||||||
# The :test delivery method accumulates sent emails in the
|
|
||||||
# ActionMailer::Base.deliveries array.
|
|
||||||
config.action_mailer.delivery_method = :test
|
|
||||||
|
|
||||||
# Raise exception on mass assignment protection for Active Record models
|
# Raise exception on mass assignment protection for Active Record models
|
||||||
config.active_record.mass_assignment_sanitizer = :strict
|
config.active_record.mass_assignment_sanitizer = :strict
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
Dummy::Application.routes.draw do
|
Dummy::Application.routes.draw do
|
||||||
scope "(:locale)", locale: /en|zh/ do
|
scope "(:locale)", locale: /en|zh/ do
|
||||||
resources :posts, only: [:show]
|
resources :posts, only: [:show] do
|
||||||
|
get "mail", on: :member
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe PostMailer do
|
||||||
|
describe "#decorated_email" do
|
||||||
|
subject { Capybara.string(email.body.to_s) }
|
||||||
|
let(:email) { PostMailer.decorated_email(post).deliver }
|
||||||
|
let(:post) { Post.create }
|
||||||
|
|
||||||
|
it "decorates" do
|
||||||
|
subject.should have_content "Today"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use path helpers with a model" do
|
||||||
|
subject.should have_css "#path_with_model", text: "/en/posts/#{post.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use path helpers with an id" do
|
||||||
|
subject.should have_css "#path_with_id", text: "/en/posts/#{post.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use url helpers with a model" do
|
||||||
|
subject.should have_css "#url_with_model", text: "http://www.example.com/en/posts/#{post.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can use url helpers with an id" do
|
||||||
|
subject.should have_css "#url_with_id", text: "http://www.example.com/en/posts/#{post.id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,48 +1,49 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'support/dummy_app'
|
require 'support/dummy_app'
|
||||||
|
|
||||||
|
shared_examples_for "a decorator in a view" do
|
||||||
|
it "works" do
|
||||||
|
# it runs in the correct environment
|
||||||
|
page.should have_css "#environment", text: environment
|
||||||
|
|
||||||
|
# it can use path helpers with a model
|
||||||
|
page.should have_css "#path_with_model", text: "/en/posts/1"
|
||||||
|
|
||||||
|
# it can use path helpers with an id
|
||||||
|
page.should have_css "#path_with_id", text: "/en/posts/1"
|
||||||
|
|
||||||
|
# it can use url helpers with a model
|
||||||
|
page.should have_css "#url_with_model", text: "http://www.example.com/en/posts/1"
|
||||||
|
|
||||||
|
# it can use url helpers with an id
|
||||||
|
page.should have_css "#url_with_id", text: "http://www.example.com/en/posts/1"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "integration" do
|
describe "integration" do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
|
||||||
environment = ENV["RAILS_ENV"].to_s
|
rails_env = ENV["RAILS_ENV"].to_s
|
||||||
raise ArgumentError, "RAILS_ENV must be development or production" unless ["development", "production"].include?(environment)
|
raise ArgumentError, "RAILS_ENV must be development or production" unless ["development", "production"].include?(rails_env)
|
||||||
|
|
||||||
app = DummyApp.new(environment)
|
app = DummyApp.new(rails_env)
|
||||||
|
|
||||||
app.start_server do
|
app.start_server do
|
||||||
describe "in #{environment}" do
|
describe "in #{rails_env}" do
|
||||||
|
let(:environment) { rails_env }
|
||||||
before { Capybara.app_host = app.url }
|
before { Capybara.app_host = app.url }
|
||||||
|
|
||||||
it "runs in the correct environment" do
|
context "in a view" do
|
||||||
visit("/posts/1")
|
before { visit("/posts/1") }
|
||||||
page.should have_css "#environment", text: environment
|
|
||||||
|
it_behaves_like "a decorator in a view"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "decorates" do
|
context "in a mailer" do
|
||||||
visit("/posts/1")
|
before { visit("/posts/1/mail") }
|
||||||
page.should have_content "Today"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can use path helpers with a model" do
|
it_behaves_like "a decorator in a view"
|
||||||
visit("/posts/1")
|
|
||||||
page.should have_css "#path_with_model", text: "/en/posts/1"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can use path helpers with an id" do
|
|
||||||
visit("/posts/1")
|
|
||||||
page.should have_css "#path_with_id", text: "/en/posts/1"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can use url helpers with a model" do
|
|
||||||
visit("/posts/1")
|
|
||||||
page.should have_css "#url_with_model", text: "http://www.example.com/en/posts/1"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can use url helpers with an id" do
|
|
||||||
visit("/posts/1")
|
|
||||||
page.should have_css "#url_with_id", text: "http://www.example.com/en/posts/1"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue