with_model 0.2.2 → 0.2.3

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.2.3
2
+
3
+ Create a new class each run to prevent test pollution. (J. Andrew Marshall)
4
+ Use :UpperCase in examples.
5
+
1
6
  ### 0.2.2
2
7
 
3
8
  The table block is now optional.
@@ -34,7 +34,7 @@ In an RSpec example group, call +with_model+ and inside its block pass it a +tab
34
34
 
35
35
  describe "A blog post" do
36
36
 
37
- with_model :blog_post do
37
+ with_model :BlogPost do
38
38
  # The table block works just like a migration.
39
39
  table do |t|
40
40
  t.string :title
@@ -58,7 +58,7 @@ In an RSpec example group, call +with_model+ and inside its block pass it a +tab
58
58
  end
59
59
 
60
60
  # with_model classes can have associations.
61
- with_model :comment do
61
+ with_model :Comment do
62
62
  table do |t|
63
63
  t.string :text
64
64
  t.belongs_to :blog_post
@@ -105,7 +105,7 @@ In an RSpec example group, call +with_model+ and inside its block pass it a +tab
105
105
  end
106
106
 
107
107
  describe "with table options" do
108
- with_model :with_options do
108
+ with_model :WithOptions do
109
109
  table :id => false do |t|
110
110
  t.string 'foo'
111
111
  t.timestamps
@@ -30,9 +30,10 @@ module WithModel
30
30
  original_const_defined = Object.const_defined?(const_name)
31
31
  original_const_value = Object.const_get(const_name) if original_const_defined
32
32
 
33
- model = Class.new(WithModel::Base)
33
+ model = nil
34
34
 
35
35
  @example_group.before do
36
+ model = Class.new(WithModel::Base)
36
37
  silence_warnings { Object.const_set(const_name, model) }
37
38
  Object.const_get(const_name).class_eval do
38
39
  set_table_name table_name
@@ -1,3 +1,3 @@
1
1
  module WithModel
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -26,7 +26,7 @@ describe "ActiveRecord behaviors" do
26
26
  RegularModel.connection.drop_table(@model.table_name) rescue nil
27
27
  end
28
28
 
29
- with_model :blog_post do
29
+ with_model :BlogPost do
30
30
  table do |t|
31
31
  t.string 'title'
32
32
  t.text 'content'
@@ -67,7 +67,7 @@ describe "ActiveRecord behaviors" do
67
67
  end
68
68
  end
69
69
 
70
- with_model :tea_cup do
70
+ with_model :TeaCup do
71
71
  table do |t|
72
72
  t.belongs_to :pet, :polymorphic => true
73
73
  end
@@ -78,7 +78,7 @@ describe "ActiveRecord behaviors" do
78
78
 
79
79
  with_table :animals
80
80
 
81
- with_model :stuffed_animal do
81
+ with_model :StuffedAnimal do
82
82
  table
83
83
  model do
84
84
  has_many :tea_cups, :as => :pet
@@ -2,7 +2,7 @@
2
2
 
3
3
  describe "A blog post" do
4
4
 
5
- with_model :blog_post do
5
+ with_model :BlogPost do
6
6
  # The table block works just like a migration.
7
7
  table do |t|
8
8
  t.string :title
@@ -26,7 +26,7 @@
26
26
  end
27
27
 
28
28
  # with_model classes can have associations.
29
- with_model :comment do
29
+ with_model :Comment do
30
30
  table do |t|
31
31
  t.string :text
32
32
  t.belongs_to :blog_post
@@ -73,7 +73,7 @@
73
73
  end
74
74
 
75
75
  describe "with table options" do
76
- with_model :with_options do
76
+ with_model :WithOptions do
77
77
  table :id => false do |t|
78
78
  t.string 'foo'
79
79
  t.timestamps
@@ -4,7 +4,7 @@ describe "a temporary ActiveRecord model created with with_model" do
4
4
  non_shadowing_example_ran = false
5
5
 
6
6
  describe "which doesn't shadow an existing class" do
7
- with_model :blog_post do
7
+ with_model :BlogPost do
8
8
  table do |t|
9
9
  t.string 'title'
10
10
  t.text 'content'
@@ -76,8 +76,7 @@ describe "a temporary ActiveRecord model created with with_model" do
76
76
  shadowing_example_ran = false
77
77
 
78
78
  describe "that shadows an existing constant" do
79
- with_model :my_const do
80
- table {}
79
+ with_model :MyConst do
81
80
  end
82
81
 
83
82
  after do
@@ -97,8 +96,7 @@ describe "a temporary ActiveRecord model created with with_model" do
97
96
  end
98
97
 
99
98
  describe "with a plural name" do
100
- with_model :blog_posts do
101
- table {}
99
+ with_model :BlogPosts do
102
100
  end
103
101
 
104
102
  it "should not singularize the constant name" do
@@ -109,7 +107,20 @@ describe "a temporary ActiveRecord model created with with_model" do
109
107
 
110
108
  describe "with a name containing capital letters" do
111
109
  with_model :BlogPost do
112
- table {}
110
+ end
111
+
112
+ it "should tableize the table name" do
113
+ BlogPost.table_name.should match(/_blog_posts_/)
114
+ BlogPost.table_name.should == BlogPost.table_name.downcase
115
+ end
116
+ end
117
+
118
+ describe "with a name with underscores" do
119
+ with_model :blog_post do
120
+ end
121
+
122
+ it "should constantize the name" do
123
+ BlogPost.should be
113
124
  end
114
125
 
115
126
  it "should tableize the table name" do
@@ -124,8 +135,7 @@ describe "a temporary ActiveRecord model created with with_model" do
124
135
  end
125
136
 
126
137
  context "with a mixin" do
127
- with_model :with_a_mixin do
128
- table {}
138
+ with_model :WithAMixin do
129
139
  model do
130
140
  include AMixin
131
141
  end
@@ -139,6 +149,35 @@ describe "a temporary ActiveRecord model created with with_model" do
139
149
  end
140
150
  end
141
151
 
152
+ context "with a mixin that has a class_eval" do
153
+ subject { WithAClassEval.new }
154
+
155
+ module AMixinWithClassEval
156
+ def self.included(klass)
157
+ klass.class_eval do
158
+ after_save { |object| object.my_method }
159
+ end
160
+ end
161
+ end
162
+
163
+ with_model :WithAClassEval do
164
+ model do
165
+ include AMixinWithClassEval
166
+ def my_method; end
167
+ end
168
+ end
169
+
170
+ it "should only have one after_save callback" do
171
+ subject.should_receive(:my_method).once
172
+ subject.save
173
+ end
174
+
175
+ it "should still only have one after_save callback in future tests" do
176
+ subject.should_receive(:my_method).once
177
+ subject.save
178
+ end
179
+ end
180
+
142
181
  if defined?(Mixico)
143
182
  context "after a context that uses a mixin" do
144
183
  it "should not have the mixin" do
@@ -149,7 +188,7 @@ describe "a temporary ActiveRecord model created with with_model" do
149
188
  end
150
189
 
151
190
  context "with table options" do
152
- with_model :with_options do
191
+ with_model :WithOptions do
153
192
  table :id => false do |t|
154
193
  t.string 'foo'
155
194
  t.timestamps
@@ -162,7 +201,7 @@ describe "a temporary ActiveRecord model created with with_model" do
162
201
  end
163
202
 
164
203
  context "without a model block" do
165
- with_model :blog_post do
204
+ with_model :BlogPost do
166
205
  table do |t|
167
206
  t.string 'title'
168
207
  t.text 'content'
@@ -196,7 +235,7 @@ describe "a temporary ActiveRecord model created with with_model" do
196
235
  end
197
236
 
198
237
  context "without a table block" do
199
- with_model :blog_post do
238
+ with_model :BlogPost do
200
239
  end
201
240
 
202
241
  it "should act like a normal ActiveRecord model" do
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "with_model"
7
7
  s.version = WithModel::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Case Commons, LLC"]
10
- s.email = ["casecommons-dev@googlegroups.com"]
9
+ s.authors = ["Case Commons, LLC", "Grant Hutchins"]
10
+ s.email = ["casecommons-dev@googlegroups.com", "gems@nertzy.com"]
11
11
  s.homepage = "https://github.com/Casecommons/with_model"
12
12
  s.summary = %q{Dynamically build a model within an Rspec context}
13
13
  s.description = s.summary
metadata CHANGED
@@ -1,42 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
4
5
  prerelease:
5
- version: 0.2.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Case Commons, LLC
9
+ - Grant Hutchins
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2011-07-11 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2011-09-02 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: activerecord
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70182266155180 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
24
22
  version: 2.3.5
25
23
  - - <
26
- - !ruby/object:Gem::Version
24
+ - !ruby/object:Gem::Version
27
25
  version: 4.0.0
28
26
  type: :runtime
29
- version_requirements: *id001
27
+ prerelease: false
28
+ version_requirements: *70182266155180
30
29
  description: Dynamically build a model within an Rspec context
31
- email:
30
+ email:
32
31
  - casecommons-dev@googlegroups.com
32
+ - gems@nertzy.com
33
33
  executables: []
34
-
35
34
  extensions: []
36
-
37
35
  extra_rdoc_files: []
38
-
39
- files:
36
+ files:
40
37
  - .autotest
41
38
  - .gitignore
42
39
  - .rspec
@@ -57,35 +54,31 @@ files:
57
54
  - spec/spec_helper.rb
58
55
  - spec/with_model_spec.rb
59
56
  - with_model.gemspec
60
- has_rdoc: true
61
57
  homepage: https://github.com/Casecommons/with_model
62
58
  licenses: []
63
-
64
59
  post_install_message:
65
60
  rdoc_options: []
66
-
67
- require_paths:
61
+ require_paths:
68
62
  - lib
69
- required_ruby_version: !ruby/object:Gem::Requirement
63
+ required_ruby_version: !ruby/object:Gem::Requirement
70
64
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
75
- required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
70
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
81
75
  requirements: []
82
-
83
76
  rubyforge_project:
84
- rubygems_version: 1.6.2
77
+ rubygems_version: 1.8.6
85
78
  signing_key:
86
79
  specification_version: 3
87
80
  summary: Dynamically build a model within an Rspec context
88
- test_files:
81
+ test_files:
89
82
  - spec/active_record_behaviors_spec.rb
90
83
  - spec/readme_spec.rb
91
84
  - spec/spec_helper.rb