lazy_mail 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.
Files changed (49) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +109 -0
  3. data/Rakefile +38 -0
  4. data/lib/lazy_mail.rb +102 -0
  5. data/lib/lazy_mail/git.rb +21 -0
  6. data/lib/lazy_mail/version.rb +3 -0
  7. data/spec/db/models.rb +11 -0
  8. data/spec/db/schema.rb +18 -0
  9. data/spec/db/seeds.rb +4 -0
  10. data/spec/dummy/README.rdoc +261 -0
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  13. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  15. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  17. data/spec/dummy/config.ru +4 -0
  18. data/spec/dummy/config/application.rb +59 -0
  19. data/spec/dummy/config/boot.rb +10 -0
  20. data/spec/dummy/config/database.yml +25 -0
  21. data/spec/dummy/config/environment.rb +5 -0
  22. data/spec/dummy/config/environments/development.rb +37 -0
  23. data/spec/dummy/config/environments/production.rb +67 -0
  24. data/spec/dummy/config/environments/test.rb +37 -0
  25. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  26. data/spec/dummy/config/initializers/inflections.rb +15 -0
  27. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  28. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  29. data/spec/dummy/config/initializers/session_store.rb +8 -0
  30. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/spec/dummy/config/locales/en.yml +5 -0
  32. data/spec/dummy/config/routes.rb +58 -0
  33. data/spec/dummy/db/test.sqlite3 +0 -0
  34. data/spec/dummy/log/development.log +4 -0
  35. data/spec/dummy/log/test.log +8156 -0
  36. data/spec/dummy/public/404.html +26 -0
  37. data/spec/dummy/public/422.html +26 -0
  38. data/spec/dummy/public/500.html +25 -0
  39. data/spec/dummy/public/favicon.ico +0 -0
  40. data/spec/dummy/script/rails +6 -0
  41. data/spec/lazy_mail/lazy_mail_spec.rb +229 -0
  42. data/spec/locales/lang_spec.yml +19 -0
  43. data/spec/notifications/my_mail_test/en/test.text.erb +1 -0
  44. data/spec/notifications/my_mail_test/en/test_client.text.erb +1 -0
  45. data/spec/notifications/my_mail_test/en/test_obj.text.erb +1 -0
  46. data/spec/notifications/my_mail_test/en/test_res.text.erb +1 -0
  47. data/spec/notifications/my_mail_test/fr/test.text.erb +1 -0
  48. data/spec/spec_helper.rb +29 -0
  49. metadata +158 -0
@@ -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,229 @@
1
+ require 'spec_helper'
2
+
3
+ class MyMailTest < ActionMailer::Base
4
+
5
+ def test(resource = User.first, options = {})
6
+ lazy_mail resource, options
7
+ end
8
+
9
+ def test_res(*args)
10
+ lazy_mail *args
11
+ end
12
+
13
+ def test_client(*args)
14
+ lazy_mail *args
15
+ end
16
+
17
+ def test_fail
18
+ lazy_mail
19
+ end
20
+
21
+ def test_obj(*args)
22
+ lazy_mail *args
23
+ end
24
+
25
+ end
26
+
27
+ describe LazyMail, :type => :mailer do
28
+
29
+ before :each do
30
+ LazyMail.user_model = User
31
+ LazyMail.default_no_reply = 'no-reply@test.com'
32
+ LazyMail.mailer_templates_path = '../../spec/notifications'
33
+ I18n.locale = :en
34
+ @user = User.first
35
+ end
36
+
37
+ describe "mail by default" do
38
+
39
+ before :each do
40
+ @mail = MyMailTest.test
41
+ end
42
+
43
+ it "should return user email" do
44
+ @mail.to.should == [ @user.email ]
45
+ end
46
+
47
+ it "should set the default from" do
48
+ @mail.from.should == [ 'no-reply@test.com' ]
49
+ end
50
+
51
+ it "should find template based on locale" do
52
+ @mail.body.should include('Hello')
53
+ end
54
+
55
+ it "should change template if locale changed" do
56
+ I18n.locale = :fr
57
+ @mail = MyMailTest.test
58
+ @mail.subject.should == 'mon test email'
59
+ @mail.body.should include('Bonjour')
60
+ end
61
+
62
+ it "should send to mail_view the user object" do
63
+ @mail.body.should include(@user.username)
64
+ end
65
+
66
+ end
67
+
68
+ describe "with options (like mail)" do
69
+
70
+ it "should change from" do
71
+ options = { :from => 'one@test.mail' }
72
+ mail = MyMailTest.test(@user, options)
73
+ mail.from.should == [ 'one@test.mail' ]
74
+ end
75
+
76
+ it "should works with many options" do
77
+ options = { :to => 'test@mail.com', :subject => 'my subject' }
78
+ mail = MyMailTest.test(@user, options)
79
+ mail.to.should == [ 'test@mail.com' ]
80
+ mail.subject.should == 'my subject'
81
+ end
82
+
83
+ it "should change the template" do
84
+ options = { :template_path => '../../spec/notifications/my_mail_test/fr' }
85
+ mail = MyMailTest.test(@user, options)
86
+ I18n.locale.should == :en
87
+ mail.body.should include('Bonjour')
88
+ end
89
+
90
+ it "option :to could have a list of emails" do
91
+ my_array = ['test@mail.com', 'test_1@mail.com', 'test_2@mail.com']
92
+ options = { :to => my_array }
93
+ mail = MyMailTest.test(@user, options)
94
+ mail.to.should == my_array
95
+ end
96
+
97
+ it "option :from could have a list of emails" do
98
+ my_array = ['test@mail.com', 'test_1@mail.com', 'test_2@mail.com']
99
+ options = { :from => my_array }
100
+ mail = MyMailTest.test(@user, options)
101
+ mail.from.should == my_array
102
+ end
103
+
104
+ it "should change the no-reply with initiatializer" do
105
+ LazyMail.default_no_reply = 'tom@no-reply-test.com'
106
+ mail = MyMailTest.test
107
+ mail.from.should == [ 'tom@no-reply-test.com' ]
108
+ end
109
+
110
+ end
111
+
112
+ describe "i18n scope" do
113
+
114
+ it "should work" do
115
+ mail = MyMailTest.test
116
+ mail.subject.should == 'my test mail'
117
+ end
118
+
119
+ it "should work with i18n default rails scope" do
120
+ LazyMail.i18n_scope = nil
121
+ mail = MyMailTest.test
122
+ mail.subject.should == 'rails default'
123
+ end
124
+
125
+ it "should work with key words" do
126
+ LazyMail.i18n_scope = [:action_name, :hey, :class_name, :test]
127
+ mail = MyMailTest.test
128
+ mail.subject.should == 'hey!'
129
+ end
130
+
131
+ end
132
+
133
+ describe "should create resouces" do
134
+
135
+ before :each do
136
+ LazyMail.user_model = User
137
+ LazyMail.email_field = :email
138
+ end
139
+
140
+ it "should works with many resources" do
141
+ mail = MyMailTest.test_res(@user, Client.first, Other.first)
142
+ mail.body.should == "tom, bob, plop"
143
+ end
144
+
145
+ it "should work with another model" do
146
+ client = Client.first
147
+ LazyMail.user_model = Client
148
+ mail = MyMailTest.test_client(@user, client)
149
+ mail.to.should == [ client.email ]
150
+ mail.body.should == "bob: tom"
151
+ end
152
+
153
+ it "should work with another name than email" do
154
+ other = Other.first
155
+ LazyMail.user_model = Other
156
+ LazyMail.email_field = :test_mail
157
+ mail = MyMailTest.test_res(@user, Client.first, other)
158
+ mail.to.should == [ other.test_mail ]
159
+ mail.body.should == "tom, bob, plop"
160
+ end
161
+
162
+ it "should raise an error without user or options[:to]" do
163
+ expect {
164
+ MyMailTest.test(Client.first)
165
+ }.to raise_error(ArgumentError)
166
+ end
167
+
168
+ it "should raise an error with no values" do
169
+ expect {
170
+ MyMailTest.test_fail
171
+ }.to raise_error(ArgumentError)
172
+ end
173
+
174
+ it "if user_model is not defined should raise an error" do
175
+ LazyMail.user_model = nil
176
+ expect {
177
+ MyMailTest.test(@user)
178
+ }.to raise_error(ArgumentError, 'lazy_mail: you need to define a user_model or use option :to')
179
+ end
180
+
181
+ it "should work with no ActiveRecord object" do
182
+ mail = MyMailTest.test_obj(@user, ['Hi'], ['haha', 'plop'], "my_string", User.find_by_username('tomtom'))
183
+ mail.body.should == "tom: Hi -> my_string - plop = tomtom"
184
+ end
185
+
186
+ end
187
+
188
+ describe "mail in development" do
189
+
190
+ before :each do
191
+ Rails.stub!(:env).and_return('development')
192
+ end
193
+
194
+ describe "with string" do
195
+
196
+ it "should overwrite user mail" do
197
+ LazyMail.development_mail = 'tom@string.com'
198
+ mail = MyMailTest.test
199
+ mail.to.should == [ 'tom@string.com' ]
200
+ end
201
+
202
+ end
203
+
204
+ describe "#git" do
205
+
206
+ before :each do
207
+ LazyMail.development_mail = :git
208
+ class TestGit
209
+ include LazyMail
210
+ end
211
+ @test_git = TestGit.new
212
+ end
213
+
214
+ it "should return current git user" do
215
+ @test_git.stub!(:user_email).and_return("test@git.com\n")
216
+ @test_git.send(:get_email).should == "test@git.com"
217
+ end
218
+
219
+ it "should return an error message" do
220
+ @test_git.stub!(:user_email).and_return("\n")
221
+ @test_git.should_receive(:warn)
222
+ @test_git.send(:get_email)
223
+ end
224
+
225
+ end
226
+
227
+ end
228
+
229
+ end
@@ -0,0 +1,19 @@
1
+ en:
2
+ mailer:
3
+ my_mail_test:
4
+ test:
5
+ subject: "my test mail"
6
+ my_mail_test:
7
+ test:
8
+ subject: "rails default"
9
+ test:
10
+ hey:
11
+ my_mail_test:
12
+ test:
13
+ subject: "hey!"
14
+
15
+ fr:
16
+ mailer:
17
+ my_mail_test:
18
+ test:
19
+ subject: "mon test email"
@@ -0,0 +1 @@
1
+ Hello <%= @user.username %>
@@ -0,0 +1 @@
1
+ <%= @client.username %>: <%= @user.username %>
@@ -0,0 +1 @@
1
+ <%= @user.username %>: <%= @array[0] %> -> <%= @string %> - <%= @array_2[1] %> = <%= @user_2.username %>
@@ -0,0 +1 @@
1
+ <%= @user.username %>, <%= @client.username %>, <%= @other.username %>
@@ -0,0 +1 @@
1
+ Bonjour <%= @user.username %>
@@ -0,0 +1,29 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
8
+
9
+
10
+ # Fixtures
11
+
12
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
13
+ ActiveRecord::Migration.verbose = false
14
+ load 'db/schema.rb'
15
+ require 'db/models'
16
+ require 'db/seeds'
17
+
18
+ # Locales
19
+
20
+ I18n.locale = :en
21
+ I18n.default_locale = :en
22
+ I18n.load_path = Dir["spec/locales/lang_spec.yml"]
23
+
24
+
25
+ RSpec.configure do |config|
26
+
27
+ config.mock_with :rspec
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lazy_mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Floch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.11.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.11.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3-ruby
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.3
78
+ description: lazy_mail is a lazy and quick way to use the function mail and offers
79
+ configurations to write less code
80
+ email:
81
+ - thomas.floch@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/lazy_mail/git.rb
87
+ - lib/lazy_mail/version.rb
88
+ - lib/lazy_mail.rb
89
+ - spec/db/models.rb
90
+ - spec/db/schema.rb
91
+ - spec/db/seeds.rb
92
+ - spec/dummy/app/assets/javascripts/application.js
93
+ - spec/dummy/app/assets/stylesheets/application.css
94
+ - spec/dummy/app/controllers/application_controller.rb
95
+ - spec/dummy/app/helpers/application_helper.rb
96
+ - spec/dummy/app/views/layouts/application.html.erb
97
+ - spec/dummy/config/application.rb
98
+ - spec/dummy/config/boot.rb
99
+ - spec/dummy/config/database.yml
100
+ - spec/dummy/config/environment.rb
101
+ - spec/dummy/config/environments/development.rb
102
+ - spec/dummy/config/environments/production.rb
103
+ - spec/dummy/config/environments/test.rb
104
+ - spec/dummy/config/initializers/backtrace_silencers.rb
105
+ - spec/dummy/config/initializers/inflections.rb
106
+ - spec/dummy/config/initializers/mime_types.rb
107
+ - spec/dummy/config/initializers/secret_token.rb
108
+ - spec/dummy/config/initializers/session_store.rb
109
+ - spec/dummy/config/initializers/wrap_parameters.rb
110
+ - spec/dummy/config/locales/en.yml
111
+ - spec/dummy/config/routes.rb
112
+ - spec/dummy/config.ru
113
+ - spec/dummy/db/test.sqlite3
114
+ - spec/dummy/log/development.log
115
+ - spec/dummy/log/test.log
116
+ - spec/dummy/public/404.html
117
+ - spec/dummy/public/422.html
118
+ - spec/dummy/public/500.html
119
+ - spec/dummy/public/favicon.ico
120
+ - spec/dummy/Rakefile
121
+ - spec/dummy/README.rdoc
122
+ - spec/dummy/script/rails
123
+ - spec/lazy_mail/lazy_mail_spec.rb
124
+ - spec/locales/lang_spec.yml
125
+ - spec/notifications/my_mail_test/en/test.text.erb
126
+ - spec/notifications/my_mail_test/en/test_client.text.erb
127
+ - spec/notifications/my_mail_test/en/test_obj.text.erb
128
+ - spec/notifications/my_mail_test/en/test_res.text.erb
129
+ - spec/notifications/my_mail_test/fr/test.text.erb
130
+ - spec/spec_helper.rb
131
+ - MIT-LICENSE
132
+ - Rakefile
133
+ - README.rdoc
134
+ homepage: http://github.com/arkes/lazy_mail
135
+ licenses: []
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: 1.3.4
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.24
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: A lazy and quick way to use the function mail
158
+ test_files: []