letter_opener_web 1.0.0 → 1.0.1

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.
data/Guardfile CHANGED
@@ -11,13 +11,4 @@ guard 'rspec' do
11
11
  watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
12
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
13
  watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
- watch('config/routes.rb') { "spec/routing" }
15
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
-
17
- # Capybara features specs
18
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
-
20
- # Turnip features and steps
21
- watch(%r{^spec/acceptance/(.+)\.feature$})
22
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
14
  end
data/README.md CHANGED
@@ -7,7 +7,7 @@ browsing sent emails.
7
7
 
8
8
  First add the gem to your development environment and run the `bundle` command to install it.
9
9
 
10
- gem 'letter_opener_web', '1.0.0.rc3', :group => :development
10
+ gem 'letter_opener_web', '1.0.0', :group => :development
11
11
 
12
12
  ## Usage
13
13
 
@@ -48,11 +48,14 @@ To prevent `rails-footnotes` from outputing debug information to your mails add
48
48
  the following to your `config/initializers/footnotes.rb`:
49
49
 
50
50
  ```ruby
51
+ notes = Footnotes::Filter.notes
51
52
  Footnotes.setup do |config|
52
53
  config.before do |controller, filter|
53
- controller.class.name =~ /LetterOpenerWeb/ ?
54
- filter.notes.clear :
55
- filter.notes
54
+ if controller.class.name =~ /LetterOpenerWeb/
55
+ filter.notes = []
56
+ else
57
+ filter.notes = notes
58
+ end
56
59
  end
57
60
  end
58
61
  ```
@@ -14,6 +14,17 @@ module LetterOpenerWeb
14
14
  render text: text
15
15
  end
16
16
 
17
+ def attachment
18
+ letter = Letter.find(params[:id])
19
+ filename = "#{params[:file]}.#{params[:format]}"
20
+
21
+ if file = letter.attachments[filename]
22
+ send_file(file, :filename => filename, :disposition => 'inline')
23
+ else
24
+ render :text => 'Attachment not found!', :status => 404
25
+ end
26
+ end
27
+
17
28
  def clear
18
29
  Letter.destroy_all
19
30
  redirect_to letters_path
@@ -44,14 +44,24 @@ module LetterOpenerWeb
44
44
  'plain'
45
45
  end
46
46
 
47
+ def attachments
48
+ @attachments ||= Dir["#{base_dir}/attachments/*"].each_with_object({}) do |file, hash|
49
+ hash[File.basename(file)] = File.expand_path(file)
50
+ end
51
+ end
52
+
47
53
  private
48
54
 
55
+ def base_dir
56
+ "#{letters_location}/#{id}"
57
+ end
58
+
49
59
  def read_file(style)
50
- File.read("#{letters_location}/#{id}/#{style}.html")
60
+ File.read("#{base_dir}/#{style}.html")
51
61
  end
52
62
 
53
63
  def style_exists?(style)
54
- File.exists?("#{letters_location}/#{id}/#{style}.html")
64
+ File.exists?("#{base_dir}/#{style}.html")
55
65
  end
56
66
 
57
67
  def adjust_link_targets(contents)
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  LetterOpenerWeb::Engine.routes.draw do
2
- delete 'clear' => 'letters#clear', as: :clear_letters
3
- get '/' => 'letters#index', as: :letters
4
- get ':id(/:style)' => 'letters#show', as: :letter
2
+ delete 'clear' => 'letters#clear', :as => :clear_letters
3
+ get '/' => 'letters#index', :as => :letters
4
+ get ':id(/:style)' => 'letters#show', :as => :letter
5
+ get ':id/attachments/:file' => 'letters#attachment'
5
6
  end
@@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
6
6
  end
7
7
 
8
8
  def send_mail
9
- ContactMailer.new_message(params[:email], params[:message]).deliver
9
+ ContactMailer.new_message(params[:email], params[:message], params[:attachment]).deliver
10
10
  redirect_to '/', :notice => 'Email sent successfully, please check letter_opener_web inbox.'
11
11
  end
12
12
  end
@@ -18,8 +18,11 @@ class ContactMailer < ActionMailer::Base
18
18
  :from => 'no-reply@letter_opener_web.com',
19
19
  :template_path => '.'
20
20
 
21
- def new_message(from, message)
21
+ def new_message(from, message, attachment)
22
22
  @from, @message = from, message
23
+ if attachment.present?
24
+ attachments[attachment.original_filename] = attachment.tempfile.read
25
+ end
23
26
  mail(:subject => 'Testing letter_opener_web', :template_name => 'new_message')
24
27
  end
25
28
  end
data/demo/index.html.erb CHANGED
@@ -29,7 +29,7 @@
29
29
  <div class="span6 offset3">
30
30
 
31
31
  <div class="well">
32
- <form method="post" action="/">
32
+ <form method="post" action="/" enctype="multipart/form-data">
33
33
  <legend>Contact form</legend>
34
34
  <div class="control-group">
35
35
  <label class="control-label" for="email">Email</label>
@@ -37,6 +37,12 @@
37
37
  <input type="text" class="input-block-level" name="email">
38
38
  </div>
39
39
  </div>
40
+ <div class="control-group">
41
+ <label class="control-label" for="attachment">Attachment <em>(optional)</em></label>
42
+ <div class="controls">
43
+ <input type='file' name='attachment' />
44
+ </div>
45
+ </div>
40
46
  <div class="control-group">
41
47
  <label class="control-label" for="message">Message</label>
42
48
  <div class="controls">
@@ -1,3 +1,3 @@
1
1
  module LetterOpenerWeb
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -47,6 +47,29 @@ describe LetterOpenerWeb::LettersController do
47
47
  end
48
48
  end
49
49
 
50
+ describe 'GET attachment' do
51
+ let(:id) { 'an-id' }
52
+ let(:attachment_path) { "path/to/attachment" }
53
+ let(:file_name) { 'image.jpg' }
54
+ let(:letter) { mock(:letter, attachments: { file_name => attachment_path}, id: id) }
55
+
56
+ before do
57
+ LetterOpenerWeb::Letter.stub(find: letter)
58
+ controller.stub(:send_file) { controller.render :nothing => true }
59
+ end
60
+
61
+ it 'sends the file as an inline attachment' do
62
+ controller.should_receive(:send_file).with(attachment_path, :filename => file_name, :disposition => 'inline')
63
+ get :attachment, id: id, file: file_name.gsub(/\.\w+/, ''), format: File.extname(file_name)[1..-1]
64
+ response.status.should == 200
65
+ end
66
+
67
+ it "throws a 404 if attachment file can't be found" do
68
+ get :attachment, id: id, file: 'unknown', format: 'woot'
69
+ response.status.should == 404
70
+ end
71
+ end
72
+
50
73
  describe 'DELETE clear' do
51
74
  it 'removes all letters' do
52
75
  LetterOpenerWeb::Letter.should_receive(:destroy_all)
@@ -1,5 +1,6 @@
1
1
  Rails.application.routes.draw do
2
- delete 'clear' => 'letter_opener_web/letters#clear'
3
- get '/' => 'letter_opener_web/letters#index', as: :letters
4
- get ':id(/:style)' => 'letter_opener_web/letters#show', as: :letter
2
+ delete 'clear' => 'letter_opener_web/letters#clear'
3
+ get '/' => 'letter_opener_web/letters#index', as: :letters
4
+ get ':id(/:style)' => 'letter_opener_web/letters#show', as: :letter
5
+ get ':id/attachments/:file' => 'letter_opener_web/letters#attachment', format: false
5
6
  end
@@ -64,6 +64,23 @@ MAIL
64
64
  end
65
65
  end
66
66
 
67
+ describe 'attachments' do
68
+ let(:file) { 'an-image.csv' }
69
+ let(:attachments_dir) { "#{location}/#{id}/attachments" }
70
+ let(:id) { '1111_1111' }
71
+
72
+ subject { described_class.new(id: id) }
73
+
74
+ before do
75
+ FileUtils.mkdir_p(attachments_dir)
76
+ File.open("#{attachments_dir}/#{file}", 'w') { |f| f.puts 'csv,contents' }
77
+ end
78
+
79
+ it 'builds a hash with file name as key and full path as value' do
80
+ subject.attachments.should == { file => "#{attachments_dir}/#{file}" }
81
+ end
82
+ end
83
+
67
84
  describe '.search' do
68
85
  let(:search_results) { described_class.search }
69
86
  let(:first_letter) { search_results.first }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_opener_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: 497055164717147357
158
+ hash: -1136549867586764880
159
159
  none: false
160
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 497055164717147357
167
+ hash: -1136549867586764880
168
168
  none: false
169
169
  requirements: []
170
170
  rubyforge_project: