email_attribute 0.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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +78 -0
  4. data/Rakefile +38 -0
  5. data/lib/email_attribute/attribute.rb +40 -0
  6. data/lib/email_attribute/email_validator.rb +30 -0
  7. data/lib/email_attribute/list.rb +57 -0
  8. data/lib/email_attribute/railtie.rb +12 -0
  9. data/lib/email_attribute/single_address.rb +31 -0
  10. data/lib/email_attribute/version.rb +3 -0
  11. data/lib/email_attribute.rb +9 -0
  12. data/lib/tasks/email_attribute_tasks.rake +4 -0
  13. data/test/dummy/README.rdoc +261 -0
  14. data/test/dummy/Rakefile +7 -0
  15. data/test/dummy/app/assets/javascripts/application.js +15 -0
  16. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  17. data/test/dummy/app/controllers/application_controller.rb +3 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/models/email.rb +11 -0
  20. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/test/dummy/config/application.rb +54 -0
  22. data/test/dummy/config/boot.rb +10 -0
  23. data/test/dummy/config/database.yml +25 -0
  24. data/test/dummy/config/environment.rb +5 -0
  25. data/test/dummy/config/environments/development.rb +33 -0
  26. data/test/dummy/config/environments/production.rb +69 -0
  27. data/test/dummy/config/environments/test.rb +33 -0
  28. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/test/dummy/config/initializers/inflections.rb +15 -0
  30. data/test/dummy/config/initializers/mime_types.rb +5 -0
  31. data/test/dummy/config/initializers/secret_token.rb +7 -0
  32. data/test/dummy/config/initializers/session_store.rb +8 -0
  33. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/test/dummy/config/locales/en.yml +5 -0
  35. data/test/dummy/config/routes.rb +58 -0
  36. data/test/dummy/config.ru +4 -0
  37. data/test/dummy/db/migrate/20130916191537_add_emails.rb +11 -0
  38. data/test/dummy/log/development.log +0 -0
  39. data/test/dummy/log/test.log +3290 -0
  40. data/test/dummy/public/404.html +26 -0
  41. data/test/dummy/public/422.html +26 -0
  42. data/test/dummy/public/500.html +25 -0
  43. data/test/dummy/public/favicon.ico +0 -0
  44. data/test/dummy/script/rails +6 -0
  45. data/test/dummy/test/fixtures/emails.yml +5 -0
  46. data/test/fixtures/emails.yml +5 -0
  47. data/test/test_helper.rb +18 -0
  48. data/test/unit/email_test.rb +37 -0
  49. data/test/unit/email_validator_test.rb +48 -0
  50. data/test/unit/list_test.rb +68 -0
  51. data/test/unit/single_address_test.rb +37 -0
  52. metadata +189 -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,5 @@
1
+ existing:
2
+ to: "foo@bar.com; Jeff Ching <ching.jeff@gmail.com>"
3
+ from: "No Reply <noreply@foo.com>"
4
+ subject: "Automatic notification"
5
+ body: "Something's ready"
@@ -0,0 +1,5 @@
1
+ existing:
2
+ to: "foo@bar.com; Jeff Ching <ching.jeff@gmail.com>"
3
+ from: "No Reply <noreply@foo.com>"
4
+ subject: "Automatic notification"
5
+ body: "Something's ready"
@@ -0,0 +1,18 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require 'shoulda/context'
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
14
+
15
+ # Load fixtures from the engine
16
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
17
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
18
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class EmailTest < ActiveSupport::TestCase
4
+
5
+ self.use_transactional_fixtures = true
6
+ fixtures :emails
7
+
8
+ test "loading from db" do
9
+ email = Email.find(ActiveRecord::Fixtures.identify(:existing))
10
+
11
+ from = email.from
12
+ assert_equal("No Reply <noreply@foo.com>", from.to_s)
13
+
14
+ to = email.to
15
+ assert_equal("foo@bar.com, Jeff Ching <ching.jeff@gmail.com>", to.to_s)
16
+ assert_equal(2, to.length)
17
+ end
18
+
19
+ test "creating" do
20
+ email = Email.new({
21
+ to: ["foo@bar.com", "bar@foo.com"],
22
+ from: "sender@foo.com",
23
+ body: "blah",
24
+ subject: "blah"
25
+ })
26
+
27
+ assert_difference "Email.count", 1 do
28
+ email.save
29
+ end
30
+
31
+ email = Email.last
32
+ assert_equal(2, email.to.length)
33
+ assert_equal("foo@bar.com, bar@foo.com", email.to.to_s)
34
+ assert_equal("sender@foo.com", email.from.to_s)
35
+ end
36
+
37
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class EmailValidatorTest < ActiveSupport::TestCase
4
+
5
+ test "validating single address" do
6
+ email = Email.new({
7
+ from: "some invalid email address",
8
+ to: "foo@bar.com",
9
+ body: "body",
10
+ subject: "subject"
11
+ })
12
+
13
+ assert_equal("some invalid email address", email.from)
14
+ assert_equal(false, email.save)
15
+ assert email.errors[:from].present?
16
+ assert email.errors[:from].first.match("custom message")
17
+ end
18
+
19
+ test "validating list addresses" do
20
+ email = Email.new({
21
+ from: "sender@foo.com",
22
+ to: "some invalid email address",
23
+ body: "body",
24
+ subject: "subject"
25
+ })
26
+
27
+ assert_equal(1, email.to.length)
28
+ assert_equal(["some invalid email address"], email.to.addresses)
29
+ assert_equal(false, email.save)
30
+ assert email.errors[:to].present?
31
+ assert email.errors[:to].first.match("another message")
32
+ end
33
+
34
+ test "validating several addresses" do
35
+ email = Email.new({
36
+ from: "sender@foo.com",
37
+ to: "some invalid email address, valid@foo.com",
38
+ body: "body",
39
+ subject: "subject"
40
+ })
41
+
42
+ assert_equal(2, email.to.length)
43
+ assert_equal(false, email.save)
44
+ assert email.errors[:to].present?
45
+ assert email.errors[:to].first.match("another message")
46
+ end
47
+
48
+ end
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+
3
+ class ListTest < ActiveSupport::TestCase
4
+ context "list attribute" do
5
+
6
+ should "handle single values" do
7
+ list = EmailAttribute::List.new("foo@bar.com")
8
+ assert_equal(1, list.length)
9
+ assert_equal("foo@bar.com", list.to_s)
10
+ end
11
+
12
+ should "handle complex single values" do
13
+ list = EmailAttribute::List.new("Jeffrey Ching <ching.jeff@gmail.com>")
14
+ assert_equal(1, list.length)
15
+ assert_equal("Jeffrey Ching <ching.jeff@gmail.com>", list.to_s)
16
+ end
17
+
18
+ should "handle bad single values" do
19
+ list = EmailAttribute::List.new("some bad value")
20
+ assert_equal(1, list.length)
21
+ assert_equal("some bad value", list.to_s)
22
+ end
23
+
24
+ should "handle empty values" do
25
+ list = EmailAttribute::List.new("")
26
+ assert_equal(0, list.length)
27
+ assert_equal("", list.to_s)
28
+ end
29
+
30
+ should "handle nil values" do
31
+ list = EmailAttribute::List.new(nil)
32
+ assert_equal(0, list.length)
33
+ assert_equal("", list.to_s)
34
+ end
35
+
36
+ should "handle array values" do
37
+ list = EmailAttribute::List.new(["foo@bar.com", "blah@blabber.com"])
38
+ assert_equal(2, list.length)
39
+ assert_equal("foo@bar.com, blah@blabber.com", list.to_s)
40
+ end
41
+
42
+ should "handle lists with comma separators" do
43
+ list = EmailAttribute::List.new("foo@bar.com, blah@blabber.com")
44
+ assert_equal(2, list.length)
45
+ assert_equal("foo@bar.com, blah@blabber.com", list.to_s)
46
+ end
47
+
48
+ should "handle lists with semicolor separators" do
49
+ list = EmailAttribute::List.new("foo@bar.com; blah@blabber.com")
50
+ assert_equal(2, list.length)
51
+ assert_equal("foo@bar.com, blah@blabber.com", list.to_s)
52
+ end
53
+
54
+ should "handle lists with complex values" do
55
+ list = EmailAttribute::List.new("foo@bar.com; Blabber <blah@blabber.com>")
56
+ assert_equal(2, list.length)
57
+ assert_equal("foo@bar.com, Blabber <blah@blabber.com>", list.to_s)
58
+ end
59
+
60
+ should 'responds to strip for strip_attributes gem' do
61
+ list = EmailAttribute::List.new(" foo@bar.com; blah@blabber.com ")
62
+ assert_equal 'foo@bar.com, blah@blabber.com', list.strip
63
+
64
+ list = EmailAttribute::List.new(" ")
65
+ assert_equal '', list.strip
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class SingleAddressTest < ActiveSupport::TestCase
4
+
5
+ context "single attribute" do
6
+ should "handle single values" do
7
+ single = EmailAttribute::SingleAddress.new("foo@bar.com")
8
+ assert_equal("foo@bar.com", single)
9
+ end
10
+
11
+ should "handle complex single values" do
12
+ single = EmailAttribute::SingleAddress.new("Jeffrey Ching <ching.jeff@gmail.com>")
13
+ assert_equal("Jeffrey Ching <ching.jeff@gmail.com>", single)
14
+ end
15
+
16
+ should "handle bad single values" do
17
+ single = EmailAttribute::SingleAddress.new("some bad value")
18
+ assert_equal("some bad value", single)
19
+ end
20
+
21
+ should "handle empty values" do
22
+ single = EmailAttribute::SingleAddress.new("")
23
+ assert_equal("", single)
24
+ end
25
+
26
+ should "handle nil values" do
27
+ single = EmailAttribute::SingleAddress.new(nil)
28
+ assert_equal("", single)
29
+ end
30
+
31
+ should 'responds to strip for strip_attributes gem' do
32
+ single = EmailAttribute::SingleAddress.new(' foo@bar.com ')
33
+ assert_equal 'foo@bar.com', single.strip
34
+ end
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_attribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Ching
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mail
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda-context
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ActiveModel field serializer for handling email addresses via Mail gem
70
+ email:
71
+ - ching.jeff@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/email_attribute/attribute.rb
77
+ - lib/email_attribute/email_validator.rb
78
+ - lib/email_attribute/list.rb
79
+ - lib/email_attribute/railtie.rb
80
+ - lib/email_attribute/single_address.rb
81
+ - lib/email_attribute/version.rb
82
+ - lib/email_attribute.rb
83
+ - lib/tasks/email_attribute_tasks.rake
84
+ - MIT-LICENSE
85
+ - Rakefile
86
+ - README.md
87
+ - test/dummy/app/assets/javascripts/application.js
88
+ - test/dummy/app/assets/stylesheets/application.css
89
+ - test/dummy/app/controllers/application_controller.rb
90
+ - test/dummy/app/helpers/application_helper.rb
91
+ - test/dummy/app/models/email.rb
92
+ - test/dummy/app/views/layouts/application.html.erb
93
+ - test/dummy/config/application.rb
94
+ - test/dummy/config/boot.rb
95
+ - test/dummy/config/database.yml
96
+ - test/dummy/config/environment.rb
97
+ - test/dummy/config/environments/development.rb
98
+ - test/dummy/config/environments/production.rb
99
+ - test/dummy/config/environments/test.rb
100
+ - test/dummy/config/initializers/backtrace_silencers.rb
101
+ - test/dummy/config/initializers/inflections.rb
102
+ - test/dummy/config/initializers/mime_types.rb
103
+ - test/dummy/config/initializers/secret_token.rb
104
+ - test/dummy/config/initializers/session_store.rb
105
+ - test/dummy/config/initializers/wrap_parameters.rb
106
+ - test/dummy/config/locales/en.yml
107
+ - test/dummy/config/routes.rb
108
+ - test/dummy/config.ru
109
+ - test/dummy/db/migrate/20130916191537_add_emails.rb
110
+ - test/dummy/log/development.log
111
+ - test/dummy/log/test.log
112
+ - test/dummy/public/404.html
113
+ - test/dummy/public/422.html
114
+ - test/dummy/public/500.html
115
+ - test/dummy/public/favicon.ico
116
+ - test/dummy/Rakefile
117
+ - test/dummy/README.rdoc
118
+ - test/dummy/script/rails
119
+ - test/dummy/test/fixtures/emails.yml
120
+ - test/fixtures/emails.yml
121
+ - test/test_helper.rb
122
+ - test/unit/email_test.rb
123
+ - test/unit/email_validator_test.rb
124
+ - test/unit/list_test.rb
125
+ - test/unit/single_address_test.rb
126
+ homepage: http://github.com/chingor13/email_attribute
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.0.3
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: ActiveModel field serializer for handling email addresses via Mail gem
150
+ test_files:
151
+ - test/dummy/app/assets/javascripts/application.js
152
+ - test/dummy/app/assets/stylesheets/application.css
153
+ - test/dummy/app/controllers/application_controller.rb
154
+ - test/dummy/app/helpers/application_helper.rb
155
+ - test/dummy/app/models/email.rb
156
+ - test/dummy/app/views/layouts/application.html.erb
157
+ - test/dummy/config/application.rb
158
+ - test/dummy/config/boot.rb
159
+ - test/dummy/config/database.yml
160
+ - test/dummy/config/environment.rb
161
+ - test/dummy/config/environments/development.rb
162
+ - test/dummy/config/environments/production.rb
163
+ - test/dummy/config/environments/test.rb
164
+ - test/dummy/config/initializers/backtrace_silencers.rb
165
+ - test/dummy/config/initializers/inflections.rb
166
+ - test/dummy/config/initializers/mime_types.rb
167
+ - test/dummy/config/initializers/secret_token.rb
168
+ - test/dummy/config/initializers/session_store.rb
169
+ - test/dummy/config/initializers/wrap_parameters.rb
170
+ - test/dummy/config/locales/en.yml
171
+ - test/dummy/config/routes.rb
172
+ - test/dummy/config.ru
173
+ - test/dummy/db/migrate/20130916191537_add_emails.rb
174
+ - test/dummy/log/development.log
175
+ - test/dummy/log/test.log
176
+ - test/dummy/public/404.html
177
+ - test/dummy/public/422.html
178
+ - test/dummy/public/500.html
179
+ - test/dummy/public/favicon.ico
180
+ - test/dummy/Rakefile
181
+ - test/dummy/README.rdoc
182
+ - test/dummy/script/rails
183
+ - test/dummy/test/fixtures/emails.yml
184
+ - test/fixtures/emails.yml
185
+ - test/test_helper.rb
186
+ - test/unit/email_test.rb
187
+ - test/unit/email_validator_test.rb
188
+ - test/unit/list_test.rb
189
+ - test/unit/single_address_test.rb