mallet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in invoicing.gemspec
3
+ # Specify your gem's dependencies in mallet.gemspec
4
4
  gemspec
5
5
 
6
6
  group :development do
@@ -1,4 +1,4 @@
1
- module Invoicing
1
+ module Mallet
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  include Rails::Generators::Migration
@@ -6,7 +6,7 @@ module Invoicing
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
8
  desc <<-CONTENT
9
- Copies the invoicing migration file to the migrations
9
+ Copies the mallet migration file to the migrations
10
10
  folder.
11
11
 
12
12
  Please run rake db:migrate once the installer is
@@ -23,7 +23,7 @@ module Invoicing
23
23
  end
24
24
 
25
25
  def create_migration_file
26
- migration_template 'migration.rb', 'db/migrate/create_invoicing_tables.rb'
26
+ migration_template 'migration.rb', 'db/migrate/create_mallet_tables.rb'
27
27
  end
28
28
  end
29
29
  end
data/lib/mallet/mail.rb CHANGED
@@ -5,6 +5,11 @@ module Mallet
5
5
 
6
6
  belongs_to :malletable, polymorphic: true
7
7
 
8
+ scope :pending, where(workflow_state: 'pending')
9
+ scope :sent, where(workflow_state: 'sent')
10
+ scope :failed, where(workflow_state: 'failed')
11
+ scope :for, lambda {|malletable| where(malletable_type: malletable.class.name, malletable_id: malletable.id)}
12
+
8
13
  validates_presence_of :mailer_class
9
14
  validates_presence_of :mailer_method
10
15
  validates_presence_of :malletable
@@ -15,9 +20,10 @@ module Mallet
15
20
  workflow do
16
21
  state :pending do
17
22
  event :deliver, :transitions_to => :sent
23
+ event :error, :transitions_to => :failed
18
24
  end
19
25
 
20
- state :error
26
+ state :failed
21
27
  state :sent
22
28
  end
23
29
 
@@ -32,6 +38,11 @@ module Mallet
32
38
  def deliver
33
39
  mailer_class.constantize.send mailer_method.to_sym, malletable
34
40
  end
41
+
42
+ def self.deliver_all!
43
+ pending.each(&:delayed_delivery)
44
+ end
45
+
35
46
  end
36
47
 
37
48
  end
@@ -1,3 +1,3 @@
1
1
  module Mallet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,18 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  describe Mallet::Mail do
4
4
 
5
+ before(:each) do
6
+ @job = Delayed::Job.create!
7
+ end
8
+
5
9
  context "on creation" do
6
10
 
7
11
  before(:each) do
8
- job = Delayed::Job.create!
12
+ job = @job
9
13
 
10
14
  @mail = Mallet::mail do
11
15
  to job
12
16
  mailer ActionMailer::Base.name
13
17
  method 'welcome'
14
18
  end
15
-
16
- @job = job
17
19
  end
18
20
 
19
21
  it "should default to a pending state" do
@@ -40,7 +42,7 @@ describe Mallet::Mail do
40
42
  context "on delivery" do
41
43
 
42
44
  before(:each) do
43
- job = Delayed::Job.create!
45
+ job = @job
44
46
 
45
47
  @mail = Mallet::mail do
46
48
  to job
@@ -60,4 +62,57 @@ describe Mallet::Mail do
60
62
 
61
63
  end
62
64
 
65
+ context "filtering mails" do
66
+
67
+ it "should filter by pending" do
68
+ job = @job
69
+
70
+ expect {
71
+ Mallet::mail do
72
+ to job
73
+ mailer ActionMailer::Base.name
74
+ method 'welcome'
75
+ end
76
+ }.to change{ Mallet::Mail.pending.count }.by(1)
77
+ end
78
+
79
+ it "should filter by sent" do
80
+ job = @job
81
+
82
+ mail = Mallet::mail do
83
+ to job
84
+ mailer ActionMailer::Base.name
85
+ method 'welcome'
86
+ end
87
+
88
+ expect {mail.error!}.to change{ Mallet::Mail.failed.count }.by(1)
89
+ end
90
+
91
+ it "should filter by failed" do
92
+ job = @job
93
+
94
+ mail = Mallet::mail do
95
+ to job
96
+ mailer ActionMailer::Base.name
97
+ method 'welcome'
98
+ end
99
+
100
+ mail.should_receive(:deliver)
101
+ expect {mail.deliver!}.to change{ Mallet::Mail.sent.count }.by(1)
102
+ end
103
+
104
+ it "should filter by malletable item" do
105
+ job = @job
106
+
107
+ expect{
108
+ mail = Mallet::mail do
109
+ to job
110
+ mailer ActionMailer::Base.name
111
+ method 'welcome'
112
+ end
113
+ }.to change{ Mallet::Mail.for(job).count }.by(1)
114
+ end
115
+
116
+ end
117
+
63
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -138,7 +138,6 @@ files:
138
138
  - README.md
139
139
  - Rakefile
140
140
  - config.ru
141
- - lib/generators/active_record/invoicing_generator.rb
142
141
  - lib/generators/active_record/mallet_generator.rb
143
142
  - lib/generators/active_record/templates/migration.rb
144
143
  - lib/mallet.rb
@@ -1,30 +0,0 @@
1
- module Mallet
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
-
6
- source_root File.expand_path("../templates", __FILE__)
7
-
8
- desc <<-CONTENT
9
- Copies the mallet migration file to the migrations
10
- folder.
11
-
12
- Please run rake db:migrate once the installer is
13
- complete.
14
-
15
- CONTENT
16
-
17
- def self.next_migration_number(dirname) #:nodoc:
18
- if ActiveRecord::Base.timestamped_migrations
19
- Time.now.utc.strftime("%Y%m%d%H%M%S")
20
- else
21
- "%.3d" % (current_migration_number(dirname) + 1)
22
- end
23
- end
24
-
25
- def create_migration_file
26
- migration_template 'migration.rb', 'db/migrate/create_mallet_tables.rb'
27
- end
28
- end
29
- end
30
- end