with_model 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.2.1
2
+
3
+ Fix a bug when the with_model name contains capital letters. Now you can
4
+ safely make calls like `with_model :BlogPost`
5
+
1
6
  ### 0.2
2
7
 
3
8
  Remove the buggy attr_accessor method for accessing with_model classes. Now
@@ -1,4 +1,5 @@
1
1
  require 'with_model/base'
2
+ require 'active_support/inflector'
2
3
 
3
4
  module WithModel
4
5
  class Dsl
@@ -8,7 +9,7 @@ module WithModel
8
9
  dsl = self
9
10
 
10
11
  @example_group = example_group
11
- @table_name = table_name = "with_model_#{name}_#{$$}"
12
+ @table_name = table_name = "with_model_#{name.to_s.tableize}_#{$$}"
12
13
  @model_initialization = lambda {|*|}
13
14
 
14
15
  const_name = name.to_s.camelize.to_sym
@@ -1,3 +1,3 @@
1
1
  module WithModel
2
- VERSION = "0.2"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -107,6 +107,17 @@ describe "a temporary ActiveRecord model created with with_model" do
107
107
  end
108
108
  end
109
109
 
110
+ describe "with a name containing capital letters" do
111
+ with_model :BlogPost do
112
+ table {}
113
+ end
114
+
115
+ it "should tableize the table name" do
116
+ BlogPost.table_name.should match(/_blog_posts_/)
117
+ BlogPost.table_name.should == BlogPost.table_name.downcase
118
+ end
119
+ end
120
+
110
121
  module AMixin
111
122
  def foo
112
123
  end
@@ -150,4 +161,38 @@ describe "a temporary ActiveRecord model created with with_model" do
150
161
  end
151
162
  end
152
163
 
164
+ context "without a model block" do
165
+ with_model :blog_post do
166
+ table do |t|
167
+ t.string 'title'
168
+ t.text 'content'
169
+ t.timestamps
170
+ end
171
+ end
172
+
173
+ it "should act like a normal ActiveRecord model" do
174
+ record = BlogPost.create!(:title => 'New blog post', :content => "Hello, world!")
175
+
176
+ record.reload
177
+
178
+ record.title.should == 'New blog post'
179
+ record.content.should == 'Hello, world!'
180
+ record.updated_at.should be_present
181
+
182
+ record.destroy
183
+
184
+ lambda {
185
+ record.reload
186
+ }.should raise_error(ActiveRecord::RecordNotFound)
187
+ end
188
+
189
+ if defined?(ActiveModel)
190
+ describe "the class" do
191
+ subject { BlogPost.new }
192
+ it_should_behave_like "ActiveModel"
193
+ end
194
+ end
195
+
196
+ end
197
+
153
198
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_model
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-21 00:00:00.000000000 -04:00
12
+ date: 2011-07-01 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &2152628080 !ruby/object:Gem::Requirement
17
+ requirement: &2164522740 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -25,7 +25,7 @@ dependencies:
25
25
  version: 4.0.0
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *2152628080
28
+ version_requirements: *2164522740
29
29
  description: Dynamically build a model within an Rspec context
30
30
  email:
31
31
  - casecommons-dev@googlegroups.com