letter_opener_web 1.3.1 → 1.3.2

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.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +27 -0
  5. data/.travis.yml +21 -4
  6. data/CHANGELOG.md +7 -0
  7. data/Gemfile +3 -7
  8. data/README.md +15 -4
  9. data/Rakefile +6 -35
  10. data/app/assets/javascripts/letter_opener_web/application.js +1 -1
  11. data/app/controllers/letter_opener_web/application_controller.rb +2 -0
  12. data/app/controllers/letter_opener_web/letters_controller.rb +19 -21
  13. data/app/models/letter_opener_web/letter.rb +27 -23
  14. data/app/views/layouts/letter_opener_web/{application.html.erb → letters.html.erb} +0 -2
  15. data/app/views/letter_opener_web/letters/index.html.erb +8 -8
  16. data/{script → bin}/rails +4 -1
  17. data/bin/setup +6 -0
  18. data/config/routes.rb +2 -0
  19. data/letter_opener_web.gemspec +13 -11
  20. data/lib/letter_opener_web.rb +20 -1
  21. data/lib/letter_opener_web/delivery_method.rb +5 -3
  22. data/lib/letter_opener_web/engine.rb +12 -7
  23. data/lib/letter_opener_web/version.rb +3 -1
  24. data/script/pre-push +2 -0
  25. data/spec/controllers/letter_opener_web/letters_controller_spec.rb +50 -32
  26. data/spec/dummy/Rakefile +8 -0
  27. data/spec/dummy/app/assets/config/manifest.js +5 -0
  28. data/spec/{internal/public/favicon.ico → dummy/app/assets/images/.keep} +0 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  30. data/spec/dummy/app/assets/stylesheets/application.css +31 -0
  31. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  32. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  33. data/spec/dummy/app/controllers/home_controller.rb +10 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  35. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  36. data/spec/dummy/app/mailers/contact_mailer.rb +14 -0
  37. data/spec/dummy/app/views/contact_mailer/new_message.html.erb +21 -0
  38. data/spec/dummy/app/views/contact_mailer/new_message.text.erb +3 -0
  39. data/spec/dummy/app/views/home/index.html.erb +50 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +18 -0
  41. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  42. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  43. data/spec/dummy/bin/bundle +5 -0
  44. data/spec/dummy/bin/rails +6 -0
  45. data/spec/dummy/bin/rake +6 -0
  46. data/spec/dummy/bin/setup +36 -0
  47. data/spec/dummy/bin/update +31 -0
  48. data/spec/dummy/config.ru +7 -0
  49. data/spec/dummy/config/application.rb +23 -0
  50. data/spec/dummy/config/boot.rb +7 -0
  51. data/spec/dummy/config/environment.rb +7 -0
  52. data/spec/dummy/config/environments/development.rb +40 -0
  53. data/spec/dummy/config/environments/production.rb +85 -0
  54. data/spec/dummy/config/environments/test.rb +37 -0
  55. data/spec/dummy/config/initializers/application_controller_renderer.rb +7 -0
  56. data/spec/dummy/config/initializers/assets.rb +13 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  58. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  59. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  60. data/spec/dummy/config/initializers/inflections.rb +17 -0
  61. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  62. data/spec/dummy/config/initializers/new_framework_defaults.rb +10 -0
  63. data/spec/dummy/config/initializers/session_store.rb +5 -0
  64. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  65. data/spec/dummy/config/locales/en.yml +23 -0
  66. data/spec/dummy/config/puma.rb +49 -0
  67. data/spec/dummy/config/routes.rb +8 -0
  68. data/spec/dummy/config/secrets.yml +22 -0
  69. data/spec/dummy/config/spring.rb +8 -0
  70. data/spec/dummy/lib/assets/.keep +0 -0
  71. data/spec/dummy/public/404.html +67 -0
  72. data/spec/dummy/public/422.html +67 -0
  73. data/spec/dummy/public/500.html +66 -0
  74. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  75. data/spec/dummy/public/apple-touch-icon.png +0 -0
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/letter_opener_web_spec.rb +44 -0
  78. data/spec/models/letter_opener_web/letter_spec.rb +23 -15
  79. data/spec/rails_helper.rb +8 -0
  80. data/spec/spec_helper.rb +2 -16
  81. metadata +142 -30
  82. data/Gemfile.lock +0 -167
  83. data/Guardfile +0 -14
  84. data/lib/tasks/letter_opener_web_tasks.rake +0 -4
  85. data/spec/internal/config/database.yml +0 -3
  86. data/spec/internal/config/routes.rb +0 -7
  87. data/spec/internal/db/schema.rb +0 -3
  88. data/spec/internal/log/.gitignore +0 -1
@@ -1,5 +1,8 @@
1
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.
2
+ # frozen_string_literal: true
3
+
4
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your
5
+ # application.
3
6
 
4
7
  ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
8
  ENGINE_PATH = File.expand_path('../../lib/letter_opener_web/engine', __FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ bundle check || bundle install
5
+
6
+ ln -sf "$(git rev-parse --show-toplevel)/script/pre-push" .git/hooks/pre-push
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  LetterOpenerWeb::Engine.routes.draw do
2
4
  delete 'clear' => 'letters#clear', :as => :clear_letters
3
5
  delete ':id' => 'letters#destroy', :as => :delete_letter
@@ -1,28 +1,30 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'letter_opener_web/version'
5
6
 
6
7
  Gem::Specification.new do |gem|
7
- gem.name = "letter_opener_web"
8
+ gem.name = 'letter_opener_web'
8
9
  gem.version = LetterOpenerWeb::VERSION
9
- gem.authors = ["Fabio Rehm"]
10
- gem.email = ["fgrehm@gmail.com"]
11
- gem.description = %q{Gives letter_opener an interface for browsing sent emails}
10
+ gem.authors = ['Fabio Rehm']
11
+ gem.email = ['fgrehm@gmail.com']
12
+ gem.description = 'Gives letter_opener an interface for browsing sent emails'
12
13
  gem.summary = gem.description
13
- gem.homepage = "https://github.com/fgrehm/letter_opener_web"
14
+ gem.homepage = 'https://github.com/fgrehm/letter_opener_web'
14
15
  gem.license = 'MIT'
15
16
 
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) }
18
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
20
+ gem.require_paths = ['lib']
20
21
 
21
- gem.add_dependency 'railties', '>= 3.2'
22
22
  gem.add_dependency 'actionmailer', '>= 3.2'
23
23
  gem.add_dependency 'letter_opener', '~> 1.0'
24
+ gem.add_dependency 'railties', '>= 3.2'
24
25
 
26
+ gem.add_development_dependency 'rails', '~> 4.2.0'
25
27
  gem.add_development_dependency 'rspec-rails', '~> 3.0'
28
+ gem.add_development_dependency 'rubocop', '~> 0.47'
26
29
  gem.add_development_dependency 'shoulda-matchers', '~> 2.5'
27
- gem.add_development_dependency 'combustion', '~> 0.5'
28
30
  end
@@ -1,5 +1,24 @@
1
- require "letter_opener_web/engine"
1
+ # frozen_string_literal: true
2
+
3
+ require 'letter_opener_web/engine'
2
4
  require 'rexml/document'
3
5
 
4
6
  module LetterOpenerWeb
7
+ class Config
8
+ attr_accessor :letters_location
9
+ end
10
+
11
+ def self.config
12
+ @config ||= Config.new.tap do |conf|
13
+ conf.letters_location = Rails.root.join('tmp', 'letter_opener')
14
+ end
15
+ end
16
+
17
+ def self.configure
18
+ yield config if block_given?
19
+ end
20
+
21
+ def self.reset!
22
+ @config = nil
23
+ end
5
24
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'letter_opener/delivery_method'
2
4
 
3
5
  module LetterOpenerWeb
4
6
  class DeliveryMethod < LetterOpener::DeliveryMethod
5
7
  def deliver!(mail)
6
- location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
7
- LetterOpener::Message.rendered_messages(location, mail)
8
- # Launchy.open(URI.parse(URI.escape(messages.first.filepath)))
8
+ ENV['LAUNCHY_DRY_RUN'] = 'true'
9
+ super
10
+ ENV['LAUNCHY_DRY_RUN'] = 'false'
9
11
  end
10
12
  end
11
13
  end
@@ -1,5 +1,4 @@
1
- # Fix for ruby 1.8.7
2
- require 'active_support/core_ext/kernel/singleton_class'
1
+ # frozen_string_literal: true
3
2
 
4
3
  require 'letter_opener'
5
4
  require 'letter_opener_web/delivery_method'
@@ -8,18 +7,24 @@ module LetterOpenerWeb
8
7
  class Engine < ::Rails::Engine
9
8
  isolate_namespace LetterOpenerWeb
10
9
 
11
- initializer "letter_opener_web.add_delivery_method" do
12
- ActionMailer::Base.add_delivery_method :letter_opener_web, LetterOpenerWeb::DeliveryMethod, :location => Rails.root.join("tmp", "letter_opener")
10
+ initializer 'letter_opener_web.add_delivery_method' do
11
+ ActiveSupport.on_load :action_mailer do
12
+ ActionMailer::Base.add_delivery_method(
13
+ :letter_opener_web,
14
+ LetterOpenerWeb::DeliveryMethod,
15
+ location: LetterOpenerWeb.config.letters_location
16
+ )
17
+ end
13
18
  end
14
19
 
15
- initializer "assets" do |app|
16
- Rails.application.config.assets.precompile += %w(
20
+ initializer 'assets' do |_app|
21
+ Rails.application.config.assets.precompile += %w[
17
22
  letter_opener_web/application.js
18
23
  letter_opener_web/application.css
19
24
  letter_opener_web/glyphicons-halflings.png
20
25
  letter_opener_web/glyphicons-halflings-white.png
21
26
  letter_opener_web/blue-dot.ico
22
- )
27
+ ]
23
28
  end
24
29
  end
25
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LetterOpenerWeb
2
- VERSION = "1.3.1"
4
+ VERSION = '1.3.2'
3
5
  end
data/script/pre-push ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ bundle exec rubocop -a
@@ -1,60 +1,76 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
2
4
 
3
5
  describe LetterOpenerWeb::LettersController do
6
+ routes { LetterOpenerWeb::Engine.routes }
7
+
8
+ after(:each) { LetterOpenerWeb.reset! }
9
+
4
10
  describe 'GET index' do
5
11
  before do
6
- allow(LetterOpenerWeb::Letter).to receive_messages(:search => :all_letters)
12
+ allow(LetterOpenerWeb::Letter).to receive(:search)
7
13
  get :index
8
14
  end
9
- it 'should assign all letters to @letters' do
10
- expect(assigns[:letters]).to eq(:all_letters)
15
+
16
+ it 'searches for all letters' do
17
+ expect(LetterOpenerWeb::Letter).to have_received(:search)
18
+ end
19
+
20
+ it 'returns an HTML 200 response' do
21
+ expect(response.status).to eq(200)
22
+ expect(response.content_type).to eq('text/html')
11
23
  end
12
24
  end
13
25
 
14
26
  describe 'GET show' do
15
27
  let(:id) { 'an-id' }
16
- # TODO: Move these to fixture files
17
- let(:rich_text) { "rich text href=\"plain.html\"" }
18
- let(:plain_text) { "plain text href=\"rich.html\"" }
19
- let(:letter) { double(:letter, :rich_text => rich_text, :plain_text => plain_text, :id => id) }
28
+ let(:rich_text) { 'rich text href="plain.html"' }
29
+ let(:plain_text) { 'plain text href="rich.html"' }
30
+ let(:letter) { double(:letter, rich_text: rich_text, plain_text: plain_text, id: id) }
31
+
32
+ shared_examples 'found letter examples' do |letter_style|
33
+ before(:each) do
34
+ expect(LetterOpenerWeb::Letter).to receive(:find).with(id).and_return(letter)
35
+ expect(letter).to receive(:exists?).and_return(true)
36
+ get :show, id: id, style: letter_style
37
+ end
20
38
 
21
- context 'rich text version' do
22
- before do
23
- allow(LetterOpenerWeb::Letter).to receive_messages(:find => letter)
24
- allow(letter).to receive_messages(:exists? => true)
25
- get :show, :id => id, :style => 'rich'
39
+ it 'renders an HTML 200 response' do
40
+ expect(response.status).to eq(200)
41
+ expect(response.content_type).to eq('text/html')
26
42
  end
43
+ end
27
44
 
28
- it "returns letter's rich text contents" do
45
+ context 'rich text version' do
46
+ include_examples 'found letter examples', 'rich'
47
+
48
+ it 'renders the rich text contents' do
29
49
  expect(response.body).to match(/^rich text/)
30
50
  end
31
51
 
32
52
  it 'fixes plain text link' do
33
53
  expect(response.body).not_to match(/href="plain.html"/)
34
- expect(response.body).to match(/href="#{Regexp.escape letter_path(:id => letter.id, :style => 'plain')}"/)
54
+ expect(response.body).to match(/href="#{Regexp.escape letter_path(id: id, style: 'plain')}"/)
35
55
  end
36
56
  end
37
57
 
38
58
  context 'plain text version' do
39
- before do
40
- allow(LetterOpenerWeb::Letter).to receive_messages(:find => letter)
41
- allow(letter).to receive_messages(:exists? => true)
42
- get :show, :id => id, :style => 'plain'
43
- end
59
+ include_examples 'found letter examples', 'plain'
44
60
 
45
- it "returns letter's plain text contents" do
61
+ it 'renders the plain text contents' do
46
62
  expect(response.body).to match(/^plain text/)
47
63
  end
48
64
 
49
65
  it 'fixes rich text link' do
50
66
  expect(response.body).not_to match(/href="rich.html"/)
51
- expect(response.body).to match(/href="#{Regexp.escape letter_path(:id => letter.id, :style => 'rich')}"/)
67
+ expect(response.body).to match(/href="#{Regexp.escape letter_path(id: id, style: 'rich')}"/)
52
68
  end
53
69
  end
54
70
 
55
71
  context 'with wrong parameters' do
56
72
  it 'should return 404 when invalid id given' do
57
- get :show, :id => id, :style => 'rich'
73
+ get :show, id: id, style: 'rich'
58
74
  expect(response.status).to eq(404)
59
75
  end
60
76
  end
@@ -62,24 +78,26 @@ describe LetterOpenerWeb::LettersController do
62
78
 
63
79
  describe 'GET attachment' do
64
80
  let(:id) { 'an-id' }
65
- let(:attachment_path) { "path/to/attachment" }
81
+ let(:attachment_path) { 'path/to/attachment' }
66
82
  let(:file_name) { 'image.jpg' }
67
- let(:letter) { double(:letter, :attachments => { file_name => attachment_path}, :id => id) }
83
+ let(:letter) { double(:letter, attachments: { file_name => attachment_path }, id: id) }
68
84
 
69
85
  before do
70
- allow(LetterOpenerWeb::Letter).to receive_messages(:find => letter)
71
- allow(controller).to receive(:send_file) { controller.render :nothing => true }
72
- allow(letter).to receive_messages(:exists? => true)
86
+ allow(LetterOpenerWeb::Letter).to receive(:find).with(id).and_return(letter)
87
+ allow(letter).to receive(:exists?).and_return(true)
73
88
  end
74
89
 
75
90
  it 'sends the file as an inline attachment' do
76
- expect(controller).to receive(:send_file).with(attachment_path, :filename => file_name, :disposition => 'inline')
77
- get :attachment, :id => id, :file => file_name.gsub(/\.\w+/, ''), :format => File.extname(file_name)[1..-1]
91
+ allow(controller).to receive(:send_file) { controller.head :ok }
92
+ get :attachment, id: id, file: file_name.gsub(/\.\w+/, ''), format: File.extname(file_name)[1..-1]
93
+
78
94
  expect(response.status).to eq(200)
95
+ expect(controller).to have_received(:send_file)
96
+ .with(attachment_path, filename: file_name, disposition: 'inline')
79
97
  end
80
98
 
81
99
  it "throws a 404 if attachment file can't be found" do
82
- get :attachment, :id => id, :file => 'unknown', :format => 'woot'
100
+ get :attachment, id: id, file: 'unknown', format: 'woot'
83
101
  expect(response.status).to eq(404)
84
102
  end
85
103
  end
@@ -102,7 +120,7 @@ describe LetterOpenerWeb::LettersController do
102
120
  it 'removes the selected letter' do
103
121
  allow_any_instance_of(LetterOpenerWeb::Letter).to receive(:exists?).and_return(true)
104
122
  expect_any_instance_of(LetterOpenerWeb::Letter).to receive(:delete)
105
- delete :destroy, :id => id
123
+ delete :destroy, id: id
106
124
  end
107
125
  end
108
126
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
4
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5
+
6
+ require_relative 'config/application'
7
+
8
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
5
+ //= link letter_opener_web_manifest.js
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,31 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
16
+
17
+ body {
18
+ padding-top: 20px;
19
+ }
20
+
21
+ .alert {
22
+ margin-top: 20px;
23
+ }
24
+
25
+ h1, .footer {
26
+ text-align: center;
27
+ }
28
+
29
+ .icon-white {
30
+ background-image: url(<%=asset_path "letter_opener_web/glyphicons-halflings-white.png"%>);
31
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class HomeController < ApplicationController
4
+ def index; end
5
+
6
+ def create
7
+ ContactMailer.new_message(params[:email], params[:message], params[:attachment]).deliver
8
+ redirect_to '/', notice: "Email sent successfully, please check letter_opener_web's inbox."
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationHelper
4
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ContactMailer < ApplicationMailer
4
+ default to: 'admin@letter_opener_web.org', from: 'no-reply@letter_opener_web.org'
5
+
6
+ def new_message(from, message, attachment)
7
+ @from = from
8
+ @message = message
9
+
10
+ attachments[attachment.original_filename] = attachment.tempfile.read if attachment.present?
11
+
12
+ mail(subject: 'Testing letter_opener_web')
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ <style type="text/css">
2
+ label { font-weight: bold; }
3
+ .from { color: #888; font-style: italic }
4
+ .message { padding-left: 10px; }
5
+ .message p:first-child { margin-top: 0; }
6
+ </style>
7
+
8
+ <h1>New message!</h1>
9
+
10
+ <p>
11
+ <label>From:</label>
12
+ <span class="from"><%= @from %></span>
13
+ </p>
14
+
15
+ <p>
16
+ <label>Message:</label>
17
+ </p>
18
+
19
+ <div class="message">
20
+ <%= simple_format @message %>
21
+ </div>