activerecord-tableless 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color --backtrace --format doc
1
+ --color --backtrace --debug --format doc
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.files = `git ls-files`.split($\)
11
11
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
- gem.version = "1.1.3"
13
+ gem.version = "1.2.0"
14
14
  gem.has_rdoc = true
15
15
 
16
16
  gem.require_paths = ["lib"]
@@ -30,4 +30,5 @@ Gem::Specification.new do |gem|
30
30
  gem.add_development_dependency('launchy', '~> 2.1')
31
31
  gem.add_development_dependency('aruba', '>= 0.5')
32
32
  gem.add_development_dependency('capybara')
33
+ gem.add_development_dependency('debugger')
33
34
  end
@@ -96,17 +96,22 @@ module ActiveRecord
96
96
  end
97
97
  end
98
98
 
99
- %w(destroy destroy_all).each do |m|
100
- eval %{
101
- def #{m}(*args)
102
- case tableless_options[:database]
103
- when :pretend_success
104
- self
105
- when :fail_fast
106
- raise NoDatabase.new("Can't ##{m} on Tableless class")
107
- end
108
- end
109
- }
99
+ def destroy(*args)
100
+ case tableless_options[:database]
101
+ when :pretend_success
102
+ self.new()
103
+ when :fail_fast
104
+ raise NoDatabase.new("Can't #destroy on Tableless class")
105
+ end
106
+ end
107
+
108
+ def destroy_all(*args)
109
+ case tableless_options[:database]
110
+ when :pretend_success
111
+ []
112
+ when :fail_fast
113
+ raise NoDatabase.new("Can't #destroy_all on Tableless class")
114
+ end
110
115
  end
111
116
 
112
117
  if ActiveRecord::VERSION::STRING < "3.0"
@@ -141,20 +146,20 @@ module ActiveRecord
141
146
  end
142
147
 
143
148
  def transaction(&block)
144
- case tableless_options[:database]
145
- when :pretend_success
149
+ # case tableless_options[:database]
150
+ # when :pretend_success
146
151
  @_current_transaction_records ||= []
147
152
  yield
148
- when :fail_fast
149
- raise NoDatabase.new("Can't #transaction on Tableless class")
150
- end
153
+ # when :fail_fast
154
+ # raise NoDatabase.new("Can't #transaction on Tableless class")
155
+ # end
151
156
  end
152
157
 
153
158
  def tableless?
154
159
  true
155
160
  end
156
161
 
157
- if ActiveRecord::VERSION::STRING < "3.1.0"
162
+ if ActiveRecord::VERSION::STRING < "3.0.0"
158
163
  else
159
164
  def table_exists?
160
165
  false
@@ -179,7 +184,15 @@ module ActiveRecord
179
184
  new
180
185
  end
181
186
  end
182
-
187
+
188
+ def connection
189
+ conn = Object.new()
190
+ def conn.quote_table_name(*args)
191
+ ""
192
+ end
193
+ conn
194
+ end
195
+
183
196
  end
184
197
 
185
198
  module InstanceMethods
@@ -188,6 +201,10 @@ module ActiveRecord
188
201
  attributes.to_a.collect{|(name,value)| escaped_var_name(name, prefix) + "=" + escape_for_url(value) if value }.compact.join("&")
189
202
  end
190
203
 
204
+ def quote_value(value, column = nil)
205
+ ""
206
+ end
207
+
191
208
  def create(*args)
192
209
  case self.class.tableless_options[:database]
193
210
  when :pretend_success
@@ -20,7 +20,8 @@ EOCLASS
20
20
  if nested
21
21
  eval <<EOCLASS
22
22
  class ArmRest < ActiveRecord::Base
23
- has_no_table
23
+ #{database ? "has_no_table :database => :#{database}" : 'has_no_table'}
24
+ belongs_to :chair
24
25
  column :id, :integer
25
26
  column :chair_id, :integer
26
27
  column :name, :string
@@ -42,17 +43,54 @@ shared_examples_for "an active record" do
42
43
  it { should respond_to :id= }
43
44
  it { should respond_to :name }
44
45
  it { should respond_to :name= }
46
+ it { should respond_to :update_attributes }
47
+ describe "#attributes=" do
48
+ before(:each){ subject.attributes=({:name => 'Jarl Friis'}) }
49
+ it "assign attributes" do
50
+ subject.name.should == 'Jarl Friis'
51
+ end
52
+ end
45
53
  end
46
54
 
47
- shared_examples_for "nested model" do
48
-
55
+ shared_examples_for "a nested active record" do
56
+ describe "conllection#build" do
57
+ specify do
58
+ subject.arm_rests.build({:name => 'nice arm_rest'}).should be_an_instance_of(ArmRest)
59
+ end
60
+ end
61
+ describe "conllection#<<" do
62
+ specify do
63
+ (subject.arm_rests << ArmRest.new({:name => 'nice arm_rest'})).should have(1).items
64
+ end
65
+ describe "result" do
66
+ before(:each) do
67
+ subject.arm_rests << [ArmRest.new({:name => 'left'}),
68
+ ArmRest.new({:name => 'right'})]
69
+ end
70
+ it "assigns nested attributes" do
71
+ subject.arm_rests[0].name.should == 'left'
72
+ subject.arm_rests[1].name.should == 'right'
73
+ end
74
+ end
75
+ end
76
+ describe "#attributes=" do
77
+ before(:each){ subject.attributes=({ :name => 'Jarl Friis',
78
+ :arm_rests_attributes => [
79
+ {:name => 'left'},
80
+ {:name => 'right'}
81
+ ]
82
+ }) }
83
+ it "assigns attributes" do
84
+ subject.name.should == 'Jarl Friis'
85
+ end
86
+ it "assigns nested attributes" do
87
+ subject.arm_rests[0].name.should == 'left'
88
+ subject.arm_rests[1].name.should == 'right'
89
+ end
90
+ end
49
91
  end
50
92
 
51
- describe "Tableless with fail_fast" do
52
- before(:all) {make_tableless_model(nil, nil)}
53
- after(:all){ remove_models }
54
- subject { Chair.new }
55
-
93
+ shared_examples_for "a tableless model with fail_fast" do
56
94
  it_behaves_like "an active record"
57
95
  describe "class" do
58
96
  if ActiveRecord::VERSION::STRING < "3.0"
@@ -112,8 +150,60 @@ describe "Tableless with fail_fast" do
112
150
  end
113
151
  end
114
152
 
115
- shared_examples_for "a succeeding database" do
153
+ describe "Tableless with fail_fast" do
154
+ before(:all) {make_tableless_model(nil, nil)}
155
+ after(:all){ remove_models }
156
+ subject { Chair.new }
157
+ it_behaves_like "a tableless model with fail_fast"
158
+ end
116
159
 
160
+ describe "Tableless nested with fail_fast" do
161
+ before(:all) {make_tableless_model(nil, true)}
162
+ after(:all){ remove_models }
163
+ describe "#new" do
164
+ it "accepts attributes" do
165
+ Chair.new(:name => "Jarl").should be_an_instance_of(Chair)
166
+ end
167
+ it "assign attributes" do
168
+ Chair.new(:name => "Jarl").name.should == "Jarl"
169
+ end
170
+ describe "with nested models" do
171
+ subject do
172
+ Chair.new(:name => "Jarl",
173
+ :arm_rests => [
174
+ ArmRest.new(:name => 'left'),
175
+ ArmRest.new(:name => 'right'),
176
+ ])
177
+ end
178
+ it {should be_an_instance_of(Chair) }
179
+ it {should have(2).arm_rests }
180
+ end
181
+ describe "with nested attributes" do
182
+ subject do
183
+ Chair.new(:name => "Jarl",
184
+ :arm_rests_attributes => [
185
+ {:name => 'left'},
186
+ {:name => 'right'},
187
+ ])
188
+ end
189
+ it {should be_an_instance_of(Chair)}
190
+ it {should have(2).arm_rests }
191
+ end
192
+ end
193
+ subject { Chair.new }
194
+ it_behaves_like "a tableless model with fail_fast"
195
+ it_behaves_like "a nested active record"
196
+ describe "#update_attributes" do
197
+ it "raises ActiveRecord::Tableless::NoDatabase" do
198
+ expect do
199
+ subject.update_attributes(:arm_chair => {:name => 'nice arm_rest'})
200
+ end.to raise_exception(StandardError)
201
+ end
202
+ end
203
+ end
204
+
205
+ shared_examples_for "a succeeding database" do
206
+ it_behaves_like "an active record"
117
207
  describe "class" do
118
208
  if ActiveRecord::VERSION::STRING < "3.0"
119
209
  describe "#find" do
@@ -122,21 +212,21 @@ shared_examples_for "a succeeding database" do
122
212
  end
123
213
  end
124
214
  describe "#find(:all)" do
125
- specify { Chair.find(:all) == []}
215
+ specify { Chair.find(:all).should == []}
126
216
  end
127
217
  else ## ActiveRecord::VERSION::STRING >= "3.0"
128
218
  describe "#all" do
129
- specify { Chair.all == []}
219
+ specify { Chair.all.should == []}
130
220
  end
131
221
  end
132
222
  describe "#create" do
133
- specify { Chair.create(:name => 'Jarl') == true }
223
+ specify { Chair.create(:name => 'Jarl').should be_an_instance_of(Chair) }
134
224
  end
135
225
  describe "#destroy" do
136
- specify { Chair.destroy(1) == true }
226
+ specify { Chair.destroy(1).should be_an_instance_of(Chair) }
137
227
  end
138
228
  describe "#destroy_all" do
139
- specify { Chair.destroy_all == true }
229
+ specify { Chair.destroy_all.should == [] }
140
230
  end
141
231
  end
142
232
 
@@ -172,7 +262,6 @@ describe "Active record with real database" do
172
262
  end
173
263
 
174
264
  subject { Chair.new(:name => 'Jarl') }
175
- it_behaves_like "an active record"
176
265
  it_behaves_like "a succeeding database"
177
266
  end
178
267
 
@@ -180,6 +269,5 @@ describe "Tableless with succeeding database" do
180
269
  before(:all) { make_tableless_model(:pretend_success, nil) }
181
270
  after(:all){ remove_models }
182
271
  subject { Chair.new(:name => 'Jarl') }
183
- it_behaves_like "an active record"
184
272
  it_behaves_like "a succeeding database"
185
273
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-tableless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-02-22 00:00:00.000000000 Z
14
+ date: 2013-02-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -173,6 +173,22 @@ dependencies:
173
173
  - - ! '>='
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
+ - !ruby/object:Gem::Dependency
177
+ name: debugger
178
+ requirement: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ type: :development
185
+ prerelease: false
186
+ version_requirements: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
176
192
  description: ActiveRecord Tableless Models provides a simple mixin for creating models
177
193
  that are not bound to the database. This approach is mostly useful for capitalizing
178
194
  on the features ActiveRecord::Validation
@@ -218,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
234
  version: '0'
219
235
  segments:
220
236
  - 0
221
- hash: 1824871736398580322
237
+ hash: 698122787109263404
222
238
  required_rubygems_version: !ruby/object:Gem::Requirement
223
239
  none: false
224
240
  requirements:
@@ -227,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
243
  version: '0'
228
244
  segments:
229
245
  - 0
230
- hash: 1824871736398580322
246
+ hash: 698122787109263404
231
247
  requirements: []
232
248
  rubyforge_project:
233
249
  rubygems_version: 1.8.24