chimpmunk 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3cdedd77cb163a90c5a283b3c8bb07d24ef9c9c
4
- data.tar.gz: 338e3a9c77dddf0fe3b8b0170102fc014e988266
3
+ metadata.gz: c60fcdbf6b7dfda454a5d0061d798af3c67d8973
4
+ data.tar.gz: 305e8d6ea4982a9dd33b117c6c0ee8e7bfd6ffac
5
5
  SHA512:
6
- metadata.gz: bf04cb13c4be53c944ce7726bbf5781d9cee7a1e7c82074e907abd8c9490c50de89ae0b4ce493f05c0e79e8daaf2cc644be70e8c9a6b5631195704d16cc44c10
7
- data.tar.gz: da88388e5fb6b2b483480c7cb69c0109f838b4802bf5e6721008e0c24d865d3d3c3581da8cf82b12bb9af55c297e10d6feebca592b600ecf053d325e48c6ea2e
6
+ metadata.gz: 0f45bdfb37ae8b43fa769e396c57459cef38d1a5f065361a8318cc203a2cd532500556343dd09881556b5d221655c8bacc5790cdb4eccbcf91e879038a54e563
7
+ data.tar.gz: 7552591f37ca4ba7e9648429999f8c8ae943f50a4f1432d883106e60a5d627c5faaa533812fc6530247944554824e8004d23e1d52b62442e1ae5e19dc0cb0b59
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,14 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in chimpmunk.gemspec
4
4
  gemspec
5
+
6
+ group :local_development do
7
+ gem 'pry'
8
+ gem 'rspec'
9
+ gem 'activerecord'
10
+ gem 'database_cleaner'
11
+ gem 'sqlite3'
12
+ gem 'shoulda-matchers'
13
+ gem 'gibbon'
14
+ gem 'paperclip'
15
+ end
data/README.md CHANGED
@@ -26,15 +26,19 @@ Run migrations
26
26
 
27
27
  $ rake db:migrate
28
28
 
29
- Set your mailchimp api key:
29
+ Set your mailchimp api key in an initializer:
30
30
 
31
31
  Gibbon::API.api_key = "your_api_key"
32
32
 
33
+ Set your domain name in an initializer:
34
+
35
+ Chimpmunk.domain_name = 'example.com'
36
+
33
37
  ## Usage
34
38
 
35
- 1. create a new model for your campaign `app/models/test_email_campaign.rb` that extends `Chimpmunk::EmailCampaign`
39
+ 1. Create a new model for your campaign `app/models/test_email_campaign.rb` that extends `Chimpmunk::EmailCampaign`
36
40
 
37
- 2. create headers, texts and images definitions for any strings, text or images needed in the campaign.
41
+ 2. Create headers, texts and images definitions for any strings, text or images needed in the campaign. These will be the same name as the MC:EDIT areas in your template
38
42
 
39
43
  ```
40
44
  headers :hero_header, :bottom_header
@@ -50,4 +50,9 @@ en:
50
50
  title: 'Refresh Email Lists'
51
51
  menu: 'Refresh Email Lists'
52
52
  breadcrumb: 'Refresh Email Lists'
53
- link: 'Refresh Email Lists'
53
+ link: 'Refresh Email Lists'
54
+ refresh_email_templates:
55
+ title: 'Refresh Email Templates'
56
+ menu: 'Refresh Email Templates'
57
+ breadcrumb: 'Refresh Email Templates'
58
+ link: 'Refresh Email Templates'
@@ -42,6 +42,7 @@ class ChimpmunkMigration < ActiveRecord::Migration
42
42
  t.integer :facebook_likes
43
43
  t.string :campaign_kind
44
44
  t.integer :template_id
45
+ t.references :email_list_group, index: true
45
46
 
46
47
  t.timestamps
47
48
  end
data/lib/chimpmunk.rb CHANGED
@@ -7,6 +7,8 @@ require 'rails_admin/chimpmunk_custom_actions.rb'
7
7
  module Chimpmunk
8
8
  extend ActiveSupport::Autoload
9
9
 
10
+ @domain_name = nil
11
+
10
12
  autoload :EmailCampaign
11
13
  autoload :EmailList
12
14
  autoload :EmailListGroup
@@ -21,4 +23,12 @@ module Chimpmunk
21
23
  def self.mailchimp
22
24
  @mailchimp ||= ::Gibbon::API.new
23
25
  end
26
+
27
+ def self.domain_name=(key)
28
+ @domain_name = key
29
+ end
30
+
31
+ def self.domain_name
32
+ @domain_name
33
+ end
24
34
  end
@@ -3,8 +3,16 @@ module Chimpmunk
3
3
  class EmailCampaign < ::ActiveRecord::Base
4
4
  attr_accessor :skip_update_callbacks, :skip_create_callbacks
5
5
 
6
- # MC:EDIT tags used in email template sections
7
- @@mc_edit_tags = []
6
+ #
7
+ # dynamic class methods for all mc_edit types
8
+ #
9
+ [:tags, :headers, :texts, :images].each do |mc_edit_type|
10
+ self.class_eval <<-EOF
11
+ def self.mc_edit_#{mc_edit_type}
12
+ @@mc_edit_#{mc_edit_type}
13
+ end
14
+ EOF
15
+ end
8
16
 
9
17
  # rails 3
10
18
  attr_accessible :title, :from_email, :from_name, :email_list_id, :subject, :email_template_id, :mailchimp_list_id, :send_date,
@@ -16,7 +24,6 @@ module Chimpmunk
16
24
  belongs_to :email_list
17
25
  belongs_to :email_template
18
26
  belongs_to :email_list_group
19
- belongs_to :email_template
20
27
 
21
28
  # Validations
22
29
  validates :subject, presence: true
@@ -39,6 +46,7 @@ module Chimpmunk
39
46
  # create header associations
40
47
  #
41
48
  def self.headers(*headers)
49
+ @@mc_edit_headers = headers
42
50
  headers.each do |header|
43
51
  has_one header.to_sym, -> { where(name: header.to_s) }, class_name: 'Chimpmunk::EmailCampaignHeader', foreign_key: :email_campaign_id
44
52
  accepts_nested_attributes_for header.to_sym, allow_destroy: true
@@ -49,6 +57,7 @@ module Chimpmunk
49
57
  # create text associations
50
58
  #
51
59
  def self.texts(*texts)
60
+ @@mc_edit_texts = texts
52
61
  texts.each do |text|
53
62
  has_one text.to_sym, -> { where(name: text.to_s) }, class_name: 'Chimpmunk::EmailCampaignText', foreign_key: :email_campaign_id
54
63
  accepts_nested_attributes_for text.to_sym, allow_destroy: true
@@ -59,6 +68,7 @@ module Chimpmunk
59
68
  # create image associations
60
69
  #
61
70
  def self.images(*images)
71
+ @@mc_edit_images = images
62
72
  images.each do |image|
63
73
  has_one image.to_sym, -> { where(name: image.to_s) }, class_name: 'Chimpmunk::EmailCampaignImage', foreign_key: :email_campaign_id
64
74
  accepts_nested_attributes_for image.to_sym, allow_destroy: true
@@ -72,14 +82,10 @@ module Chimpmunk
72
82
  @@mc_edit_tags = mc_edit_tags
73
83
  end
74
84
 
75
- def self.mc_edit_tags
76
- @@mc_edit_tags
77
- end
78
-
79
85
  #
80
86
  # create has_many associations
81
87
  #
82
- def self.associated(association_type = :many, *associations)
88
+ def self.associated(association_type, *associations)
83
89
  associations.each do |association|
84
90
  association_name = "email_campaign_#{association}".to_sym
85
91
  send("has_#{association_type}", association_name, foreign_key: 'email_campaign_id')
@@ -95,11 +101,11 @@ module Chimpmunk
95
101
  title: campaign["title"],
96
102
  campaign_kind: campaign["type"],
97
103
  mailchimp_list_id: campaign["list_id"],
98
- email_list_id: Chimpmunk::EmailList.find_by_mailchimp_id(campaign["list_id"]),
104
+ email_list_id: Chimpmunk::EmailList.find_by_mailchimp_id(campaign["list_id"]).try(:id),
99
105
  subject: campaign["subject"],
100
106
  from_email: campaign["from_email"],
101
107
  from_name: campaign["from_name"],
102
- template_id: campaign["template_id"],
108
+ email_template_id: campaign["template_id"],
103
109
  mailchimp_campaign_id: campaign["id"]
104
110
  }
105
111
  unless self.where(campaign_attributes).any?
@@ -191,11 +197,25 @@ module Chimpmunk
191
197
  def content
192
198
  sections = {}
193
199
 
194
- @@tags.each do |tag|
195
- directory = "chimpmunk"
200
+ # headers
201
+ @@mc_edit_headers.each do |tag|
202
+ sections[tag] = self.send(tag).text
203
+ end
204
+
205
+ # texts
206
+ @@mc_edit_texts.each do |tag|
207
+ sections[tag] = self.send(tag).text
208
+ end
209
+
210
+ # images
211
+ @@mc_edit_images.each do |tag|
212
+ sections[tag] = "<img src='http://#{Chimpmunk.domain_name}#{self.send(tag).image.url}' />"
213
+ end
196
214
 
197
- if File.directory?("app/views/#{directory}") && !Dir["app/views/#{directory}/_#{tag}**"].empty?
198
- sections[tag] = action_view.render "#{directory}/#{tag}", campaign: self
215
+ # editable areas (partials)
216
+ @@mc_edit_tags.each do |tag|
217
+ if File.directory?("app/views/chimpmunk") && !Dir["app/views/chimpmunk/_#{tag}**"].empty?
218
+ sections[tag] = action_view.render "chimpmunk/#{tag}", campaign: self
199
219
  end
200
220
  end
201
221
 
@@ -252,7 +272,7 @@ module Chimpmunk
252
272
  return false
253
273
  end
254
274
 
255
- if response["errors"].empty?
275
+ if response["errors"].blank?
256
276
  data = response["data"]
257
277
  self.mailchimp_list_id = data["list_id"]
258
278
  self.title = data["title"]
@@ -8,12 +8,26 @@ module Chimpmunk
8
8
  # Assocaitions
9
9
  has_many :email_campaigns
10
10
 
11
+ #
12
+ # refresh list of templates from mailchimp
13
+ #
14
+ def self.refresh_email_templates
15
+ Chimpmunk.mailchimp.templates.list()["user"].each do |template|
16
+ EmailTemplate.find_or_create_by(
17
+ mailchimp_id: "#{template["id"]}",
18
+ name: template["name"],
19
+ layout: template["layout"],
20
+ preview_image: template["preview_image"]
21
+ )
22
+ end
23
+ end
24
+
11
25
  private
12
26
 
13
27
  if defined?(RailsAdmin)
14
28
  rails_admin do
15
29
  navigation_label 'Mailchimp'
16
- visible false
30
+ # visible false
17
31
  show do
18
32
  field :name
19
33
  field :layout
@@ -23,6 +37,17 @@ module Chimpmunk
23
37
  end
24
38
  end
25
39
  end
40
+ edit do
41
+ field :mailchimp_id do
42
+ read_only true
43
+ end
44
+ field :name do
45
+ read_only true
46
+ end
47
+ field :preview_image do
48
+ read_only :true
49
+ end
50
+ end
26
51
  end
27
52
  end
28
53
  end
@@ -1,3 +1,3 @@
1
1
  module Chimpmunk
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -20,6 +20,10 @@ module Chimpmunk
20
20
 
21
21
  inject_into_file rails_admin_initializer, after: 'config.actions do' do <<-'TEMPLATE'
22
22
 
23
+ refresh_email_templates do
24
+ only 'Chimpmunk::EmailTemplate'
25
+ end
26
+
23
27
  refresh_email_campaigns do
24
28
  only 'Chimpmunk::EmailCampaign'
25
29
  end
@@ -5,6 +5,25 @@ module RailsAdmin
5
5
  module Config
6
6
  module Actions
7
7
 
8
+ class RefreshEmailTemplates < RailsAdmin::Config::Actions::Base
9
+ RailsAdmin::Config::Actions.register(self)
10
+
11
+ register_instance_option :collection? do
12
+ true
13
+ end
14
+
15
+ register_instance_option :link_icon do
16
+ 'icon-refresh'
17
+ end
18
+
19
+ register_instance_option :controller do
20
+ Proc.new do
21
+ @abstract_model.model_name.constantize.refresh_email_templates()
22
+ redirect_to rails_admin.index_path('chimpmunk~email_template')
23
+ end
24
+ end
25
+ end
26
+
8
27
  #
9
28
  # Refresh Email Lists
10
29
  #
@@ -0,0 +1,164 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chimpmunk::EmailCampaign do
4
+ before do
5
+ @email_list = Chimpmunk::EmailList.new(name: 'test list', mailchimp_id: 1)
6
+ @email_list.id = 1
7
+ @email_list.save
8
+ @email_template = Chimpmunk::EmailTemplate.new(name: 'test template')
9
+ @email_template.id = 1
10
+ @email_template.save
11
+ paperclip_stubs()
12
+ gibbon_stubs()
13
+ end
14
+
15
+ let(:email_campaign) { Chimpmunk::EmailCampaign.create(email_list: @email_list, email_template: @email_template, subject: 'test subject', from_email: 'nf@the42.com', from_name: 'test') }
16
+
17
+ describe 'Associations' do
18
+ it { should belong_to(:email_list) }
19
+ it { should belong_to(:email_template) }
20
+ it { should belong_to(:email_list_group) }
21
+ end
22
+
23
+ describe 'Validations' do
24
+ it { should validate_presence_of(:subject) }
25
+ it { should validate_presence_of(:from_email) }
26
+ it { should validate_presence_of(:from_name) }
27
+ it { should validate_presence_of(:email_list) }
28
+ it { should validate_presence_of(:email_template) }
29
+ end
30
+
31
+ describe "Filters" do
32
+
33
+ before(:each) do
34
+ @email_campaign = Chimpmunk::EmailCampaign.new(email_list: @email_list, email_template: @email_template, subject: 'test subject', from_email: 'nf@the42.com', from_name: 'test')
35
+ end
36
+
37
+ describe 'create' do
38
+ it "should call 'create_campaign' on create" do
39
+ expect(@email_campaign).to receive(:create_campaign)
40
+ @email_campaign.save
41
+ end
42
+
43
+ it 'should skip create_campaign callback' do
44
+ expect(@email_campaign).to_not receive(:create_campaign)
45
+ @email_campaign.skip_create_callbacks = true
46
+ @email_campaign.save
47
+ end
48
+ end
49
+
50
+ describe 'update' do
51
+ it "should call 'update_campaign' on update" do
52
+ @email_campaign.save
53
+ @email_campaign.skip_update_callbacks = false
54
+ expect(@email_campaign).to receive(:update_campaign)
55
+ @email_campaign.update(subject: 'test update')
56
+ end
57
+
58
+ it "should not call 'update_campaign' on update" do
59
+ @email_campaign.save
60
+ @email_campaign.skip_update_callbacks = true
61
+ expect(@email_campaign).to_not receive(:update_campaign)
62
+ @email_campaign.update(subject: 'test update')
63
+ end
64
+
65
+ it "should call 'update_content' on update if the template id changed" do
66
+ @email_campaign.save
67
+ @email_campaign.skip_update_callbacks = false
68
+
69
+ expect(@email_campaign).to receive(:update_content)
70
+ new_template = Chimpmunk::EmailTemplate.create(name: 'new template')
71
+ @email_campaign.update(email_template_id: new_template.id)
72
+ end
73
+
74
+ it "should not call 'update_content' on update if the template id didn't change" do
75
+ @email_campaign.save
76
+ @email_campaign.skip_update_callbacks = false
77
+
78
+ expect(@email_campaign).to_not receive(:update_content)
79
+ @email_campaign.update(subject: 'new subject')
80
+ end
81
+ end
82
+
83
+ describe 'destroy' do
84
+ it "should call 'destroy_mailcimp_campaign' on destroy" do
85
+ @email_campaign.save
86
+ expect(@email_campaign).to receive(:destroy_mailchimp_campaign)
87
+ @email_campaign.destroy
88
+ end
89
+ end
90
+
91
+ describe 'class methods' do
92
+ before do
93
+ class TestEmailCampaign < Chimpmunk::EmailCampaign
94
+ headers :header_one
95
+ texts :text_one, :text_two
96
+ images :image_one, :image_two
97
+ editable_areas :first
98
+ associated :many, :posts
99
+ associated :one, :trip_hop_album
100
+ end
101
+ @test_email_campaign = TestEmailCampaign.new
102
+ end
103
+
104
+ describe 'dynamic associations' do
105
+ describe 'headers' do
106
+ it 'should create the correct header associations' do
107
+ expect(@test_email_campaign).to respond_to(:header_one)
108
+ end
109
+
110
+ it 'should create the correct type for header' do
111
+ expect(@test_email_campaign.build_header_one).to be_a(Chimpmunk::EmailCampaignHeader)
112
+ end
113
+ end
114
+
115
+ describe 'texts' do
116
+ it 'should create the correct text associations' do
117
+ expect(@test_email_campaign).to respond_to(:text_one) && respond_to(:text_two)
118
+ end
119
+
120
+ it 'should create the correct type for text' do
121
+ expect(@test_email_campaign.build_text_one).to be_a(Chimpmunk::EmailCampaignText)
122
+ end
123
+ end
124
+
125
+ describe 'images' do
126
+ it 'should create the correct image associations' do
127
+ expect(@test_email_campaign).to respond_to(:text_one) && respond_to(:text_two)
128
+ end
129
+
130
+ it 'should create the correct type for image' do
131
+ expect(@test_email_campaign.build_image_one).to be_a(Chimpmunk::EmailCampaignImage)
132
+ end
133
+ end
134
+
135
+ describe 'editable areas' do
136
+ it 'should have the correct editable areas' do
137
+ expect(TestEmailCampaign.mc_edit_tags).to include(:first)
138
+ end
139
+ end
140
+
141
+ describe 'associated' do
142
+ it 'should have_many :posts' do
143
+ expect(TestEmailCampaign.reflect_on_all_associations(:has_many).map(&:name)).to include(:email_campaign_posts)
144
+ end
145
+
146
+ it 'should have_one :trip_hop_album' do
147
+ expect(TestEmailCampaign.reflect_on_all_associations(:has_one).map(&:name)).to include(:email_campaign_trip_hop_album)
148
+ end
149
+ end
150
+ end
151
+
152
+ describe 'refresh_email_campaigns' do
153
+ it 'should create a new campaign' do
154
+ expect{Chimpmunk::EmailCampaign.refresh_email_campaigns}.to change{Chimpmunk::EmailCampaign.count}.by(1)
155
+ end
156
+ end
157
+
158
+ describe 'refresh_email_campaign_stats' do
159
+
160
+ end
161
+ end
162
+
163
+ end
164
+ end
@@ -0,0 +1,121 @@
1
+ ActiveRecord::Schema.define version: 0 do
2
+ # create email lists
3
+ create_table :email_lists do |t|
4
+ t.string :default_from_email
5
+ t.string :default_from_name
6
+ t.string :default_subject
7
+ t.string :mailchimp_id
8
+ t.string :name
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ # create email campaigns
14
+ create_table :email_campaigns do |t|
15
+ t.string :title
16
+ t.string :from_email
17
+ t.string :from_name
18
+ t.references :email_list, index: true
19
+ t.string :subject
20
+ t.references :email_template, index: true
21
+ t.string :mailchimp_list_id
22
+ t.datetime :send_date
23
+ t.string :mailchimp_campaign_id
24
+ t.string :mailchimp_list_id
25
+ t.integer :emails_sent
26
+ t.integer :clicked
27
+ t.integer :opened
28
+ t.string :status
29
+ t.integer :hard_bounces
30
+ t.integer :soft_bounces
31
+ t.integer :unsubscribes
32
+ t.integer :forwards
33
+ t.integer :forwards_opens
34
+ t.integer :opens
35
+ t.datetime :last_open
36
+ t.integer :unique_opens
37
+ t.integer :non_unique_clicks
38
+ t.integer :users_who_clicked
39
+ t.integer :unique_likes
40
+ t.integer :facebook_likes
41
+ t.string :campaign_kind
42
+ t.integer :template_id
43
+ t.references :email_list_group, index: true
44
+
45
+ t.timestamps
46
+ end
47
+
48
+ # create email list groups
49
+ create_table :email_list_groups do |t|
50
+ t.string :name
51
+ t.references :grouping, index: true
52
+
53
+ t.timestamps
54
+ end
55
+
56
+ # create email templates
57
+ create_table :email_templates do |t|
58
+ t.string :mailchimp_id
59
+ t.string :name
60
+ t.string :layout
61
+ t.string :preview_image
62
+
63
+ t.timestamps
64
+ end
65
+
66
+ # create email list groupings
67
+ create_table :email_list_groupings do |t|
68
+ t.string :name
69
+ t.references :email_list, index: true
70
+ t.integer :mailchimp_grouping_id
71
+
72
+ t.timestamps
73
+ end
74
+
75
+ # ceate email subscribers
76
+ create_table :email_subscribers do |t|
77
+ t.string :mailchimp_id
78
+ t.string :first_name
79
+ t.string :last_name
80
+ t.string :email
81
+ t.boolean :subscribed
82
+ t.references :email_list, index: true
83
+
84
+ t.timestamps
85
+ end
86
+
87
+ # create email list group subscribers join table
88
+ create_table :email_list_groups_subscribers, id: false do |t|
89
+ t.integer :email_list_group_id
90
+ t.integer :email_subscriber_id
91
+ end
92
+
93
+ create_table :email_campaign_headers do |t|
94
+ t.references :email_campaign, index: true
95
+ t.string :text
96
+ t.string :name
97
+
98
+ t.timestamps
99
+ end
100
+
101
+ create_table :email_campaign_texts do |t|
102
+ t.references :email_campaign, index: true
103
+ t.text :text
104
+ t.string :name
105
+
106
+ t.timestamps
107
+ end
108
+
109
+ create_table :email_campaign_images do |t|
110
+ t.references :email_campaign, index: true
111
+ t.string :name
112
+ t.string :image_file_name
113
+ t.string :image_content_type
114
+ t.integer :image_file_size
115
+ t.datetime :image_updated_at
116
+
117
+ t.timestamps
118
+ end
119
+
120
+ # add_attachment :email_campaign_images, :image
121
+ end
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH << '.' unless $LOAD_PATH.include?('.')
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
+ require 'logger'
4
+
5
+ require 'active_record'
6
+ require 'gibbon'
7
+
8
+ module Chimpmunk
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :EmailCampaign
12
+ autoload :EmailList
13
+ autoload :EmailListGroup
14
+ autoload :EmailListGrouping
15
+ autoload :EmailSubscriber
16
+ autoload :EmailTemplate
17
+ autoload :EmailCampaignHeader
18
+ autoload :EmailCampaignText
19
+ autoload :EmailCampaignImage
20
+ autoload :VERSION
21
+
22
+ def self.mailchimp
23
+ @mailchimp ||= ::Gibbon::API.new
24
+ end
25
+ end
26
+
27
+ # require 'rails'
28
+ require 'paperclip'
29
+ require 'rspec'
30
+ require 'database_cleaner'
31
+ require 'shoulda/matchers'
32
+ require 'pry'
33
+
34
+ Gibbon::API.api_key = '12345678'
35
+
36
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
@@ -0,0 +1,30 @@
1
+ require 'logger'
2
+
3
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
4
+ # ActiveRecord::Base.logger = Logger.new(STDOUT)
5
+
6
+ load(File.dirname(__FILE__) + '/../internal/db/schema.rb')
7
+
8
+ require 'database_cleaner'
9
+
10
+ RSpec.configure do |config|
11
+
12
+ config.before(:suite) do
13
+ DatabaseCleaner.clean_with(:truncation)
14
+ DatabaseCleaner.strategy = :transaction
15
+ DatabaseCleaner.clean
16
+ end
17
+
18
+ config.after(:suite) do
19
+ DatabaseCleaner.clean
20
+ end
21
+
22
+ config.before(:each) do
23
+ DatabaseCleaner.start
24
+ end
25
+
26
+ config.after(:each) do
27
+ DatabaseCleaner.clean
28
+ end
29
+
30
+ end
@@ -0,0 +1,39 @@
1
+ def paperclip_stubs
2
+ allow_any_instance_of(Object).to receive(:rails_admin)
3
+ allow_any_instance_of(Object).to receive(:has_attached_file)
4
+ allow_any_instance_of(Object).to receive(:validates_attachment_content_type)
5
+ end
6
+
7
+ def gibbon_stubs
8
+ allow_any_instance_of(Gibbon::APICategory).to receive(:create).and_return({})
9
+ allow_any_instance_of(Gibbon::APICategory).to receive(:update).and_return({'data' => {'list_id' => 9999, 'title' => 'title', 'subject' => 'subject', 'from_name' => 'from name', 'from_email' => 'from email'}})
10
+ allow_any_instance_of(Gibbon::APICategory).to receive(:delete)
11
+ allow_any_instance_of(Gibbon::APICategory).to receive(:list).and_return(
12
+ {'data' => [
13
+ {
14
+ 'title' => 'refreshed',
15
+ 'type' => 'test',
16
+ 'list_id' => 1,
17
+ 'subject' => 'test subject',
18
+ 'from_email' => 'new@from.test',
19
+ 'from_name' => 'test name',
20
+ 'template_id' => 1,
21
+ 'id' => 99999
22
+ }
23
+ ]}
24
+ )
25
+ allow_any_instance_of(Gibbon::APICategory).to receive(:list).with({status:"sent"}).and_return(
26
+ {'data' => [
27
+ {
28
+ 'title' => 'refreshed',
29
+ 'type' => 'test',
30
+ 'list_id' => 1,
31
+ 'subject' => 'test subject',
32
+ 'from_email' => 'new@from.test',
33
+ 'from_name' => 'test name',
34
+ 'template_id' => 1,
35
+ 'id' => 99999
36
+ }
37
+ ]}
38
+ )
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chimpmunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Franken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-13 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -94,6 +94,7 @@ extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
96
  - ".gitignore"
97
+ - ".rspec"
97
98
  - Gemfile
98
99
  - LICENSE.txt
99
100
  - README.md
@@ -115,6 +116,11 @@ files:
115
116
  - lib/chimpmunk/version.rb
116
117
  - lib/generators/chimpmunk/install_generator.rb
117
118
  - lib/rails_admin/chimpmunk_custom_actions.rb
119
+ - spec/chimpmunk/email_campaign_spec.rb
120
+ - spec/internal/db/schema.rb
121
+ - spec/spec_helper.rb
122
+ - spec/support/active_record.rb
123
+ - spec/support/stubs.rb
118
124
  homepage: https://bitbucket.org/42dev/chimpmunk
119
125
  licenses:
120
126
  - MIT
@@ -139,4 +145,9 @@ rubygems_version: 2.2.2
139
145
  signing_key:
140
146
  specification_version: 4
141
147
  summary: Mailchimp list administration and Campaign builder.
142
- test_files: []
148
+ test_files:
149
+ - spec/chimpmunk/email_campaign_spec.rb
150
+ - spec/internal/db/schema.rb
151
+ - spec/spec_helper.rb
152
+ - spec/support/active_record.rb
153
+ - spec/support/stubs.rb