acts_as_icontact 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{acts_as_icontact}
5
- s.version = "0.1.5"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Stephen Eley"]
9
- s.date = %q{2009-07-25}
9
+ s.date = %q{2009-07-26}
10
10
  s.description = %q{ActsAsIcontact connects Ruby applications with the iContact e-mail marketing service using the iContact API v2.0. Building on the RestClient gem, it offers two significant feature sets:
11
11
 
12
12
  * Simple, consistent access to all resources in the iContact API; and
@@ -24,10 +24,13 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "acts_as_icontact.gemspec",
27
+ "init.rb",
27
28
  "lib/acts_as_icontact.rb",
28
29
  "lib/acts_as_icontact/config.rb",
29
30
  "lib/acts_as_icontact/connection.rb",
30
31
  "lib/acts_as_icontact/exceptions.rb",
32
+ "lib/acts_as_icontact/rails.rb",
33
+ "lib/acts_as_icontact/rails/macro.rb",
31
34
  "lib/acts_as_icontact/resource.rb",
32
35
  "lib/acts_as_icontact/resource_collection.rb",
33
36
  "lib/acts_as_icontact/resources/account.rb",
@@ -35,8 +38,11 @@ Gem::Specification.new do |s|
35
38
  "lib/acts_as_icontact/resources/contact.rb",
36
39
  "lib/acts_as_icontact/resources/list.rb",
37
40
  "lib/acts_as_icontact/resources/message.rb",
41
+ "rails/init.rb",
38
42
  "spec/config_spec.rb",
39
43
  "spec/connection_spec.rb",
44
+ "spec/examples/schema.rb",
45
+ "spec/rails_spec.rb",
40
46
  "spec/resource_collection_spec.rb",
41
47
  "spec/resource_spec.rb",
42
48
  "spec/resources/account_spec.rb",
@@ -45,8 +51,10 @@ Gem::Specification.new do |s|
45
51
  "spec/resources/list_spec.rb",
46
52
  "spec/resources/message_spec.rb",
47
53
  "spec/spec.opts",
48
- "spec/spec_fakeweb.rb",
49
- "spec/spec_helper.rb"
54
+ "spec/spec_helper.rb",
55
+ "spec/support/active_record/connection_adapters/nulldb_adapter.rb",
56
+ "spec/support/nulldb_rspec.rb",
57
+ "spec/support/spec_fakeweb.rb"
50
58
  ]
51
59
  s.homepage = %q{http://github.com/SFEley/acts_as_icontact}
52
60
  s.rdoc_options = ["--charset=UTF-8"]
@@ -57,6 +65,8 @@ Gem::Specification.new do |s|
57
65
  s.test_files = [
58
66
  "spec/config_spec.rb",
59
67
  "spec/connection_spec.rb",
68
+ "spec/examples/schema.rb",
69
+ "spec/rails_spec.rb",
60
70
  "spec/resource_collection_spec.rb",
61
71
  "spec/resource_spec.rb",
62
72
  "spec/resources/account_spec.rb",
@@ -64,8 +74,10 @@ Gem::Specification.new do |s|
64
74
  "spec/resources/contact_spec.rb",
65
75
  "spec/resources/list_spec.rb",
66
76
  "spec/resources/message_spec.rb",
67
- "spec/spec_fakeweb.rb",
68
- "spec/spec_helper.rb"
77
+ "spec/spec_helper.rb",
78
+ "spec/support/active_record/connection_adapters/nulldb_adapter.rb",
79
+ "spec/support/nulldb_rspec.rb",
80
+ "spec/support/spec_fakeweb.rb"
69
81
  ]
70
82
 
71
83
  if s.respond_to? :specification_version then
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,15 @@
1
+ module ActsAsIcontact
2
+ module Rails
3
+ module ClassMethods
4
+ module Macro
5
+
6
+ # The core macro for ActsAsIcontact's Rails integration. Establishes callbacks to keep Rails models in
7
+ # sync with iContact. See the README for more on what it does.
8
+ def acts_as_icontact(options = {})
9
+ true
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # Load all of our Rails files
2
+ Dir[File.join(File.dirname(__FILE__), 'rails', '*.rb')].sort.each do |path|
3
+ filename = File.basename(path, '.rb')
4
+ require "acts_as_icontact/rails/#{filename}"
5
+ end
6
+
7
+ module ActsAsIcontact
8
+ module Rails
9
+ module ClassMethods
10
+ include Macro
11
+ end
12
+ end
13
+ end
14
+
15
+ if defined?(::ActiveRecord)
16
+ module ::ActiveRecord
17
+ class Base
18
+ extend ActsAsIcontact::Rails::ClassMethods
19
+ end
20
+ end
21
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Load our Rails integration code
2
+ require 'acts_as_icontact'
3
+ require 'acts_as_icontact/rails'
@@ -0,0 +1,15 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table "people", :force => true do |t|
3
+ t.string "firstName"
4
+ t.string "surname"
5
+ t.string "email", :null => false
6
+ t.string "icontact_status"
7
+ t.string "status"
8
+ t.string "icontact_id"
9
+ t.datetime "icontact_created"
10
+ t.string "bounces"
11
+ t.string "custom_field"
12
+ t.datetime "created_at"
13
+ t.datetime "updated_at"
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'activerecord'
4
+ require 'rails/init'
5
+
6
+ # Dummy model
7
+ class Person < ActiveRecord::Base
8
+ # create_table "people", :force => true do |t|
9
+ # t.string "firstName"
10
+ # t.string "surname"
11
+ # t.string "email", :null => false
12
+ # t.string "icontact_status"
13
+ # t.string "status"
14
+ # t.string "icontact_id"
15
+ # t.datetime "icontact_created"
16
+ # t.string "bounces"
17
+ # t.string "custom_field"
18
+ # t.datetime "created_at"
19
+ # t.datetime "updated_at"
20
+ # end
21
+
22
+ acts_as_icontact
23
+ end
24
+
25
+ describe "Rails integration" do
26
+ before(:all) do
27
+ ActiveRecord::Base.establish_connection :adapter => :nulldb,
28
+ :schema => File.dirname(__FILE__) + '/examples/schema.rb'
29
+ end
30
+
31
+ it "relies on a model with an email address" do
32
+ @person = Person.new(:email => "john@example.org")
33
+ @person.email.should == "john@example.org"
34
+ end
35
+
36
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'spec'
2
2
 
3
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support'))
4
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
6
  require 'acts_as_icontact'
6
7
 
7
- require 'spec_fakeweb'
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
11
 
9
12
  Spec::Runner.configure do |config|
10
13
  # config.after(:each) do
@@ -0,0 +1,217 @@
1
+ require 'logger'
2
+ require 'stringio'
3
+ require 'singleton'
4
+ require 'activerecord'
5
+ require 'active_record/connection_adapters/abstract_adapter'
6
+
7
+ class ActiveRecord::Base
8
+ # Instantiate a new NullDB connection. Used by ActiveRecord internally.
9
+ def self.nulldb_connection(config)
10
+ ActiveRecord::ConnectionAdapters::NullDBAdapter.new(config)
11
+ end
12
+ end
13
+
14
+ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
15
+ ActiveRecord::ConnectionAdapters::AbstractAdapter
16
+
17
+ class Statement
18
+ attr_reader :entry_point, :content
19
+
20
+ def initialize(entry_point, content = "")
21
+ @entry_point, @content = entry_point, content
22
+ end
23
+
24
+ def ==(other)
25
+ self.entry_point == other.entry_point
26
+ end
27
+ end
28
+
29
+ class Checkpoint < Statement
30
+ def initialize
31
+ super(:checkpoint, "")
32
+ end
33
+
34
+ def ==(other)
35
+ self.class == other.class
36
+ end
37
+ end
38
+
39
+ TableDefinition = ActiveRecord::ConnectionAdapters::TableDefinition
40
+
41
+ class NullObject
42
+ def method_missing(*args, &block)
43
+ nil
44
+ end
45
+ end
46
+
47
+ # A convenience method for integratinginto RSpec. See README for example of
48
+ # use.
49
+ def self.insinuate_into_spec(config)
50
+ config.before :all do
51
+ ActiveRecord::Base.establish_connection(:adapter => :nulldb)
52
+ end
53
+
54
+ config.after :all do
55
+ ActiveRecord::Base.establish_connection(:test)
56
+ end
57
+ end
58
+
59
+ # Recognized options:
60
+ #
61
+ # [+:schema+] path to the schema file, relative to RAILS_ROOT
62
+ def initialize(config={})
63
+ @log = StringIO.new
64
+ @logger = Logger.new(@log)
65
+ @last_unique_id = 0
66
+ @tables = {'schema_info' => TableDefinition.new(nil)}
67
+ @schema_path = config.fetch(:schema){ "db/schema.rb" }
68
+ super(nil, @logger)
69
+ end
70
+
71
+ # A log of every statement that has been "executed" by this connection adapter
72
+ # instance.
73
+ def execution_log
74
+ (@execution_log ||= [])
75
+ end
76
+
77
+ # A log of every statement that has been "executed" since the last time
78
+ # #checkpoint! was called, or since the connection was created.
79
+ def execution_log_since_checkpoint
80
+ checkpoint_index = @execution_log.rindex(Checkpoint.new)
81
+ checkpoint_index = checkpoint_index ? checkpoint_index + 1 : 0
82
+ @execution_log[(checkpoint_index..-1)]
83
+ end
84
+
85
+ # Inserts a checkpoint in the log. See also #execution_log_since_checkpoint.
86
+ def checkpoint!
87
+ self.execution_log << Checkpoint.new
88
+ end
89
+
90
+ def adapter_name
91
+ "NullDB"
92
+ end
93
+
94
+ def supports_migrations?
95
+ true
96
+ end
97
+
98
+ def create_table(table_name, options = {})
99
+ table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(self)
100
+ unless options[:id] == false
101
+ table_definition.primary_key(options[:primary_key] || "id")
102
+ end
103
+
104
+ yield table_definition
105
+
106
+ @tables[table_name] = table_definition
107
+ end
108
+
109
+ def add_fk_constraint(*args)
110
+ # NOOP
111
+ end
112
+
113
+ def add_pk_constraint(*args)
114
+ # NOOP
115
+ end
116
+
117
+ # Retrieve the table names defined by the schema
118
+ def tables
119
+ @tables.keys.map(&:to_s)
120
+ end
121
+
122
+ # Retrieve table columns as defined by the schema
123
+ def columns(table_name, name = nil)
124
+ if @tables.size <= 1
125
+ ActiveRecord::Migration.verbose = false
126
+ Kernel.load(File.join(@schema_path))
127
+ end
128
+ table = @tables[table_name]
129
+ table.columns.map do |col_def|
130
+ ActiveRecord::ConnectionAdapters::Column.new(col_def.name.to_s,
131
+ col_def.default,
132
+ col_def.type,
133
+ col_def.null)
134
+ end
135
+ end
136
+
137
+ def execute(statement, name = nil)
138
+ self.execution_log << Statement.new(entry_point, statement)
139
+ NullObject.new
140
+ end
141
+
142
+ def insert(statement, name, primary_key, object_id, sequence_name)
143
+ returning(object_id || next_unique_id) do
144
+ with_entry_point(:insert) do
145
+ super(statement, name, primary_key, object_id, sequence_name)
146
+ end
147
+ end
148
+ end
149
+
150
+ def update(statement, name=nil)
151
+ with_entry_point(:update) do
152
+ super(statement, name)
153
+ end
154
+ end
155
+
156
+ def delete(statement, name=nil)
157
+ with_entry_point(:delete) do
158
+ super(statement, name)
159
+ end
160
+ end
161
+
162
+ def select_all(statement, name=nil)
163
+ with_entry_point(:select_all) do
164
+ super(statement, name)
165
+ end
166
+ end
167
+
168
+ def select_one(statement, name=nil)
169
+ with_entry_point(:select_one) do
170
+ super(statement, name)
171
+ end
172
+ end
173
+
174
+ def select_value(statement, name=nil)
175
+ with_entry_point(:select_value) do
176
+ super(statement, name)
177
+ end
178
+ end
179
+
180
+ protected
181
+
182
+ def select(statement, name)
183
+ returning([]) do
184
+ self.execution_log << Statement.new(entry_point, statement)
185
+ end
186
+ end
187
+
188
+ private
189
+
190
+ def next_unique_id
191
+ @last_unique_id += 1
192
+ end
193
+
194
+ def with_entry_point(method)
195
+ if entry_point.nil?
196
+ with_thread_local_variable(:entry_point, method) do
197
+ yield
198
+ end
199
+ else
200
+ yield
201
+ end
202
+ end
203
+
204
+ def entry_point
205
+ Thread.current[:entry_point]
206
+ end
207
+
208
+ def with_thread_local_variable(name, value)
209
+ old_value = Thread.current[name]
210
+ Thread.current[name] = value
211
+ begin
212
+ yield
213
+ ensure
214
+ Thread.current[name] = old_value
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,93 @@
1
+ require 'active_record/connection_adapters/nulldb_adapter'
2
+
3
+ module NullDB
4
+ module RSpec
5
+ end
6
+ end
7
+
8
+ module NullDB::RSpec::NullifiedDatabase
9
+ NullDBAdapter = ActiveRecord::ConnectionAdapters::NullDBAdapter
10
+
11
+ class HaveExecuted
12
+
13
+ def initialize(entry_point)
14
+ @entry_point = entry_point
15
+ end
16
+
17
+ def matches?(connection)
18
+ log = connection.execution_log_since_checkpoint
19
+ if entry_point == :anything
20
+ not log.empty?
21
+ else
22
+ log.include?(NullDBAdapter::Statement.new(@entry_point))
23
+ end
24
+ end
25
+
26
+ def description
27
+ "connection should execute #{@entry_point} statement"
28
+ end
29
+
30
+ def failure_message
31
+ " did not execute #{@entry_point} statement when it should have"
32
+ end
33
+
34
+ def negative_failure_message
35
+ " executed #{@entry_point} statement when it should not have"
36
+ end
37
+ end
38
+
39
+ def self.globally_nullify_database
40
+ Spec::Runner.configure do |config|
41
+ nullify_database(config)
42
+ end
43
+ end
44
+
45
+ def self.contextually_nullify_database(context)
46
+ nullify_database(context)
47
+ end
48
+
49
+ # A matcher for asserting that database statements have (or have not) been
50
+ # executed. Usage:
51
+ #
52
+ # ActiveRecord::Base.connection.should have_executed(:insert)
53
+ #
54
+ # The types of statement that can be matched mostly mirror the public
55
+ # operations available in
56
+ # ActiveRecord::ConnectionAdapters::DatabaseStatements:
57
+ # - :select_one
58
+ # - :select_all
59
+ # - :select_value
60
+ # - :insert
61
+ # - :update
62
+ # - :delete
63
+ # - :execute
64
+ #
65
+ # There is also a special :anything symbol that will match any operation.
66
+ def have_executed(entry_point)
67
+ HaveExecuted.new(entry_point)
68
+ end
69
+
70
+ private
71
+
72
+ def self.included(other)
73
+ if other.ancestors.include?(Spec::Rails::Example::RailsExampleGroup)
74
+ contextually_nullify_database(other)
75
+ else
76
+ globally_nullify_database
77
+ end
78
+ end
79
+
80
+ def self.nullify_database(receiver)
81
+ receiver.before :all do
82
+ ActiveRecord::Base.establish_connection(:adapter => :nulldb)
83
+ end
84
+
85
+ receiver.before :each do
86
+ ActiveRecord::Base.connection.checkpoint!
87
+ end
88
+
89
+ receiver.after :all do
90
+ ActiveRecord::Base.establish_connection(:test)
91
+ end
92
+ end
93
+ end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_icontact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Eley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-25 00:00:00 -04:00
12
+ date: 2009-07-26 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -34,10 +34,13 @@ files:
34
34
  - Rakefile
35
35
  - VERSION
36
36
  - acts_as_icontact.gemspec
37
+ - init.rb
37
38
  - lib/acts_as_icontact.rb
38
39
  - lib/acts_as_icontact/config.rb
39
40
  - lib/acts_as_icontact/connection.rb
40
41
  - lib/acts_as_icontact/exceptions.rb
42
+ - lib/acts_as_icontact/rails.rb
43
+ - lib/acts_as_icontact/rails/macro.rb
41
44
  - lib/acts_as_icontact/resource.rb
42
45
  - lib/acts_as_icontact/resource_collection.rb
43
46
  - lib/acts_as_icontact/resources/account.rb
@@ -45,8 +48,11 @@ files:
45
48
  - lib/acts_as_icontact/resources/contact.rb
46
49
  - lib/acts_as_icontact/resources/list.rb
47
50
  - lib/acts_as_icontact/resources/message.rb
51
+ - rails/init.rb
48
52
  - spec/config_spec.rb
49
53
  - spec/connection_spec.rb
54
+ - spec/examples/schema.rb
55
+ - spec/rails_spec.rb
50
56
  - spec/resource_collection_spec.rb
51
57
  - spec/resource_spec.rb
52
58
  - spec/resources/account_spec.rb
@@ -55,8 +61,10 @@ files:
55
61
  - spec/resources/list_spec.rb
56
62
  - spec/resources/message_spec.rb
57
63
  - spec/spec.opts
58
- - spec/spec_fakeweb.rb
59
64
  - spec/spec_helper.rb
65
+ - spec/support/active_record/connection_adapters/nulldb_adapter.rb
66
+ - spec/support/nulldb_rspec.rb
67
+ - spec/support/spec_fakeweb.rb
60
68
  has_rdoc: true
61
69
  homepage: http://github.com/SFEley/acts_as_icontact
62
70
  licenses: []
@@ -88,6 +96,8 @@ summary: Automatic bridge between iContact e-mail marketing service and Rails Ac
88
96
  test_files:
89
97
  - spec/config_spec.rb
90
98
  - spec/connection_spec.rb
99
+ - spec/examples/schema.rb
100
+ - spec/rails_spec.rb
91
101
  - spec/resource_collection_spec.rb
92
102
  - spec/resource_spec.rb
93
103
  - spec/resources/account_spec.rb
@@ -95,5 +105,7 @@ test_files:
95
105
  - spec/resources/contact_spec.rb
96
106
  - spec/resources/list_spec.rb
97
107
  - spec/resources/message_spec.rb
98
- - spec/spec_fakeweb.rb
99
108
  - spec/spec_helper.rb
109
+ - spec/support/active_record/connection_adapters/nulldb_adapter.rb
110
+ - spec/support/nulldb_rspec.rb
111
+ - spec/support/spec_fakeweb.rb