msg 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ FactoryGirl.define do
4
4
  factory :bounce, :class => 'Msg::Bounce' do
5
5
  factory :valid_bounce do
6
6
  association :envelope, factory: :valid_envelope
7
+ email "test@spanner.org"
7
8
  end
8
9
  end
9
10
  end
@@ -9,9 +9,9 @@ module Msg
9
9
  @bounce = FactoryGirl.create(:valid_bounce)
10
10
  end
11
11
 
12
- it "should require an envelope" do
12
+ it "should require an email address" do
13
13
  @bounce.should be_valid
14
- @bounce.envelope = nil
14
+ @bounce.email = nil
15
15
  @bounce.should_not be_valid
16
16
  end
17
17
 
@@ -20,10 +20,6 @@ module Msg
20
20
  @envelope.should_not be_valid
21
21
  end
22
22
 
23
- it "should generate a tracker url" do
24
- pending "tracker?"
25
- end
26
-
27
23
  it "should by default be marked unopened" do
28
24
  @envelope.opened_at.should be_nil
29
25
  end
@@ -48,14 +44,13 @@ module Msg
48
44
  @envelope.from_address.should eq "#{@message.from_name} <#{@message.from_address}>"
49
45
  end
50
46
 
51
- it "should render the message contents and append a tracker dot" do
52
- @envelope.send(:render_with_tracker).should eq "#{@message.body}<img src=\"#{@envelope.url_to_open}\" />"
53
- end
54
-
55
47
  it "should send the message" do
56
48
  @envelope.send(:send_email)
57
49
  @envelope.sent_at.should_not be_nil
58
- pending "test for send"
50
+ mail = ActionMailer::Base.deliveries.last
51
+ mail[:from].to_s.should == @envelope.from_address
52
+ mail[:subject].to_s.should == @envelope.subject
53
+ mail[:message_id].to_s.should == @envelope.email_id.to_s
59
54
  end
60
55
 
61
56
  end
@@ -6,10 +6,6 @@ module Msg
6
6
  # Receivers must define a for_email method, which returns the hash we pass to the mustache
7
7
  # template. In the dummy we can use any old value just to test that they get through.
8
8
  it "should interpolate values provided by the receiver"
9
-
10
- # after rendering and before sending we have to strip out anything foolish or malicious
11
- # that has been entered by a user.
12
- it "should sanitize html in the rendered template"
13
9
  it "should accept tags allowed in Msg configuration"
14
10
  it "should reject tags not allowed in Msg configuration"
15
11
  it "should accept attributes allowed in Msg configuration"
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe "Bounce notification" do
4
+
5
+ it "creates some Bounce objects" do
6
+ envelope = FactoryGirl.create(:valid_envelope)
7
+ bounce = {
8
+ "notificationType" => "Bounce",
9
+ "bounce" => {
10
+ "bounceType" => "Permanent",
11
+ "reportingMTA" => "dns; email.example.com",
12
+ "bouncedRecipients" => [
13
+ {
14
+ "emailAddress" => "username@example.com",
15
+ "status" => "5.1.1",
16
+ "action" => "failed",
17
+ "diagnosticCode" => "smtp; 550 5.1.1 <username@example.com>... User"
18
+ },
19
+ {
20
+ "emailAddress" => "othername@example.com"
21
+ }
22
+ ],
23
+ "bounceSubType" => "General",
24
+ "timestamp" => "2012-06-19T01:07:52.000Z",
25
+ "feedbackId" => "00000138111222aa-33322211-cccc-cccc-cccc-ddddaaaa068a-000000"
26
+ },
27
+ "mail" => {
28
+ "timestamp" => "2012-06-19T01:05:45.000Z",
29
+ "source" => "sender@example.com",
30
+ "messageId" => envelope.email_id,
31
+ "destination" => [
32
+ "username@example.com"
33
+ ]
34
+ }
35
+ }
36
+
37
+ post msg.bounces_url, bounce.to_json, {'x-amz-sns-message-type' => "Notification", 'Content-Type' => 'text/plain; charset=UTF-8'}
38
+ expect(response).to be_success
39
+ end
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe "SNS subscription confirmation" do
4
+
5
+ it "calls the given url" do
6
+ envelope = FactoryGirl.create(:valid_envelope)
7
+ confirmation = {
8
+ "Type" => "SubscriptionConfirmation",
9
+ "MessageId" => "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
10
+ "Token" => "2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
11
+ "TopicArn" => "arn:aws:sns:us-east-1:123456789012:MyTopic",
12
+ "Message" => "You have chosen to subscribe to the topic arn:aws:sns:us-east-1:123456789012:MyTopic. To confirm the subscription, visit the SubscribeURL included in this message.",
13
+ "SubscribeURL" => "https://amazonses.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-1:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
14
+ "Timestamp" => "2012-04-26T20:45:04.751Z",
15
+ "SignatureVersion" => "1",
16
+ "Signature" => "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
17
+ "SigningCertURL" => "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
18
+ }
19
+
20
+ post msg.bounces_url, confirmation.to_json, {'x-amz-sns-message-type' => "SubscriptionConfirmation", 'Content-Type' => 'text/plain; charset=UTF-8'}
21
+ expect(response).to be_success
22
+ FakeWeb.should have_requested(:get, "https://amazonses.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-1:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736")
23
+ end
24
+
25
+ end
@@ -3,28 +3,23 @@ module Msg
3
3
  describe SendingsController do
4
4
  describe "routing" do
5
5
  it "routes to #index" do
6
- pending
7
- get("/sendings").should route_to("msg/sendings#index")
6
+ get("/msg/sendings").should route_to("msg/sendings#index")
8
7
  end
9
8
 
10
9
  it "routes to #show" do
11
- pending
12
- get("/sendings/1").should route_to("msg/sendings#show", :id => "1")
10
+ get("/msg/sendings/1").should route_to("msg/sendings#show", :id => "1")
13
11
  end
14
12
 
15
13
  it "routes to #new" do
16
- pending
17
- get("/sendings/new").should route_to("msg/sendings#new")
14
+ get("/msg/sendings/new").should route_to("msg/sendings#new")
18
15
  end
19
16
 
20
17
  it "routes to #create" do
21
- pending
22
- post("/sendings").should route_to("msg/sendings#create")
18
+ post("/msg/sendings").should route_to("msg/sendings#create")
23
19
  end
24
20
 
25
21
  it "routes to #destroy" do
26
- pending
27
- delete("/sendings/1").should route_to("msg/sendings#destroy", :id => "1")
22
+ delete("/msg/sendings/1").should route_to("msg/sendings#destroy", :id => "1")
28
23
  end
29
24
  end
30
25
  end
@@ -12,6 +12,9 @@ Spork.prefork do
12
12
  require 'factory_girl_rails'
13
13
  require 'database_cleaner'
14
14
  require 'email_spec'
15
+ require 'fakeweb'
16
+ require 'fakeweb_matcher'
17
+
15
18
  # Requires supporting ruby files with custom matchers and macros, etc,
16
19
  # in spec/support/ and its subdirectories.
17
20
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
@@ -47,6 +50,8 @@ Spork.prefork do
47
50
  config.before(:suite) do
48
51
  DatabaseCleaner.strategy = :transaction
49
52
  DatabaseCleaner.clean_with(:truncation)
53
+ FakeWeb.allow_net_connect = false
54
+ FakeWeb.register_uri(:get, %r|https://amazonses\.com/\?|, :body => "What ho!")
50
55
  end
51
56
  config.before(:each) do
52
57
  DatabaseCleaner.start
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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-04-10 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -140,7 +140,7 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: httpclient
143
+ name: httparty
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
@@ -298,6 +298,7 @@ files:
298
298
  - config/routes.rb
299
299
  - db/migrate/20130320141926_msg_data.rb
300
300
  - db/migrate/20130327134754_sending_circumstances.rb
301
+ - db/migrate/20130423091642_bounced_recipients.rb
301
302
  - lib/msg/engine.rb
302
303
  - lib/msg/receivers.rb
303
304
  - lib/msg/version.rb
@@ -336,7 +337,6 @@ files:
336
337
  - spec/dummy/config.ru
337
338
  - spec/dummy/db/development.sqlite3
338
339
  - spec/dummy/db/migrate/2013032210540_users.rb
339
- - spec/dummy/db/migrate/20130326093048_msg_data.msg.rb
340
340
  - spec/dummy/db/schema.rb
341
341
  - spec/dummy/db/test.sqlite3
342
342
  - spec/dummy/log/development.log
@@ -361,6 +361,8 @@ files:
361
361
  - spec/models/msg/envelope_spec.rb
362
362
  - spec/models/msg/message_spec.rb
363
363
  - spec/models/msg/sending_spec.rb
364
+ - spec/requests/bounce_notification_spec.rb
365
+ - spec/requests/sns_confirmation_spec.rb
364
366
  - spec/routing/sendings_routing_spec.rb
365
367
  - spec/spec_helper.rb
366
368
  homepage: https://github.com/spanner/msg
@@ -417,7 +419,6 @@ test_files:
417
419
  - spec/dummy/config.ru
418
420
  - spec/dummy/db/development.sqlite3
419
421
  - spec/dummy/db/migrate/2013032210540_users.rb
420
- - spec/dummy/db/migrate/20130326093048_msg_data.msg.rb
421
422
  - spec/dummy/db/schema.rb
422
423
  - spec/dummy/db/test.sqlite3
423
424
  - spec/dummy/log/development.log
@@ -442,5 +443,7 @@ test_files:
442
443
  - spec/models/msg/envelope_spec.rb
443
444
  - spec/models/msg/message_spec.rb
444
445
  - spec/models/msg/sending_spec.rb
446
+ - spec/requests/bounce_notification_spec.rb
447
+ - spec/requests/sns_confirmation_spec.rb
445
448
  - spec/routing/sendings_routing_spec.rb
446
449
  - spec/spec_helper.rb
@@ -1,55 +0,0 @@
1
- # This migration comes from msg (originally 20130320141926)
2
- class MsgData < ActiveRecord::Migration
3
- def change
4
- create_table :msg_messages do |t|
5
- t.string :subject
6
- t.string :from_address
7
- t.string :from_name
8
- t.text :body
9
- t.string :function
10
- t.text :description
11
- t.boolean :transactional, :default => false
12
- t.boolean :saved, :default => false
13
- t.integer :created_by_id
14
- t.timestamps
15
- end
16
-
17
- create_table :msg_sendings do |t|
18
- t.integer :message_id
19
- t.integer :created_by_id
20
- t.datetime :sent_at
21
- t.timestamps
22
- end
23
- add_index :msg_sendings, :message_id
24
- add_index :msg_sendings, :created_by_id
25
-
26
- create_table :msg_envelopes do |t|
27
- t.integer :sending_id
28
- t.integer :receiver_id
29
- t.integer :email_id
30
- t.string :receiver_type
31
- t.string :to_address
32
- t.string :from_address
33
- t.string :subject
34
- t.text :contents
35
- t.datetime :sent_at
36
- t.datetime :opened_at
37
- t.timestamps
38
- end
39
- add_index :msg_envelopes, :sending_id
40
- add_index :msg_envelopes, :email_id
41
- add_index :msg_envelopes, :receiver_id
42
- add_index :msg_envelopes, [:receiver_id, :receiver_type]
43
-
44
- create_table :msg_bounces do |t|
45
- t.integer :envelope_id
46
- t.string :bounce_type
47
- t.string :bounce_subtype
48
- t.string :reporter
49
- t.text :raw_message
50
- t.timestamps
51
- end
52
- add_index :msg_bounces, :envelope_id
53
-
54
- end
55
- end