activerecord-tableless 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
|
13
|
+
gem.version = "1.1.3"
|
14
14
|
gem.has_rdoc = true
|
15
15
|
|
16
16
|
gem.require_paths = ["lib"]
|
@@ -143,6 +143,7 @@ module ActiveRecord
|
|
143
143
|
def transaction(&block)
|
144
144
|
case tableless_options[:database]
|
145
145
|
when :pretend_success
|
146
|
+
@_current_transaction_records ||= []
|
146
147
|
yield
|
147
148
|
when :fail_fast
|
148
149
|
raise NoDatabase.new("Can't #transaction on Tableless class")
|
@@ -224,6 +225,12 @@ module ActiveRecord
|
|
224
225
|
end
|
225
226
|
end
|
226
227
|
|
228
|
+
if ActiveRecord::VERSION::STRING < "3.0"
|
229
|
+
else
|
230
|
+
def add_to_transaction
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
227
234
|
private
|
228
235
|
|
229
236
|
def escaped_var_name(name, prefix = nil)
|
@@ -3,67 +3,89 @@ require 'active_record'
|
|
3
3
|
require 'activerecord-tableless'
|
4
4
|
require 'logger'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
def make_tableless_model(database = nil, nested = nil)
|
7
|
+
eval <<EOCLASS
|
8
|
+
class Chair < ActiveRecord::Base
|
9
|
+
#{database ? "has_no_table :database => :#{database}" : 'has_no_table'}
|
10
|
+
column :id, :integer
|
11
|
+
column :name, :string
|
12
|
+
#{if nested
|
13
|
+
'
|
14
|
+
has_many :arm_rests
|
15
|
+
accepts_nested_attributes_for :arm_rests
|
16
|
+
'
|
17
|
+
end}
|
18
|
+
end
|
19
|
+
EOCLASS
|
20
|
+
if nested
|
21
|
+
eval <<EOCLASS
|
22
|
+
class ArmRest < ActiveRecord::Base
|
23
|
+
has_no_table
|
24
|
+
column :id, :integer
|
25
|
+
column :chair_id, :integer
|
26
|
+
column :name, :string
|
27
|
+
end
|
28
|
+
EOCLASS
|
29
|
+
end
|
13
30
|
end
|
14
31
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
column :name, :string
|
32
|
+
def remove_models
|
33
|
+
Object.send(:remove_const, :Chair) rescue nil
|
34
|
+
Object.send(:remove_const, :ArmRest) rescue nil
|
19
35
|
end
|
20
36
|
|
21
|
-
|
37
|
+
ActiveRecord::Base.logger = Logger.new(STDERR)
|
38
|
+
ActiveRecord::Base.logger.level = Logger::Severity::UNKNOWN
|
22
39
|
|
23
|
-
|
40
|
+
shared_examples_for "an active record" do
|
24
41
|
it { should respond_to :id }
|
25
42
|
it { should respond_to :id= }
|
26
43
|
it { should respond_to :name }
|
27
44
|
it { should respond_to :name= }
|
45
|
+
end
|
28
46
|
|
47
|
+
shared_examples_for "nested model" do
|
48
|
+
|
29
49
|
end
|
30
50
|
|
31
51
|
describe "Tableless with fail_fast" do
|
32
|
-
|
33
|
-
|
52
|
+
before(:all) {make_tableless_model(nil, nil)}
|
53
|
+
after(:all){ remove_models }
|
54
|
+
subject { Chair.new }
|
34
55
|
|
56
|
+
it_behaves_like "an active record"
|
35
57
|
describe "class" do
|
36
58
|
if ActiveRecord::VERSION::STRING < "3.0"
|
37
59
|
describe "#find" do
|
38
60
|
it "raises ActiveRecord::Tableless::NoDatabase" do
|
39
|
-
expect {
|
61
|
+
expect { Chair.find(1) }.to raise_exception(ActiveRecord::Tableless::NoDatabase)
|
40
62
|
end
|
41
63
|
end
|
42
64
|
describe "#find(:all)" do
|
43
65
|
it "raises ActiveRecord::Tableless::NoDatabase" do
|
44
|
-
expect {
|
66
|
+
expect { Chair.find(:all) }.to raise_exception(ActiveRecord::Tableless::NoDatabase)
|
45
67
|
end
|
46
68
|
end
|
47
69
|
else ## ActiveRecord::VERSION::STRING >= "3.0"
|
48
70
|
describe "#all" do
|
49
71
|
it "raises ActiveRecord::Tableless::NoDatabase" do
|
50
|
-
expect {
|
72
|
+
expect { Chair.all }.to raise_exception(ActiveRecord::Tableless::NoDatabase)
|
51
73
|
end
|
52
74
|
end
|
53
75
|
end
|
54
76
|
describe "#create" do
|
55
77
|
it "raises ActiveRecord::Tableless::NoDatabase" do
|
56
|
-
expect {
|
78
|
+
expect { Chair.create(:name => 'Jarl') }.to raise_exception(ActiveRecord::Tableless::NoDatabase)
|
57
79
|
end
|
58
80
|
end
|
59
81
|
describe "#destroy" do
|
60
82
|
it "raises ActiveRecord::Tableless::NoDatabase" do
|
61
|
-
expect {
|
83
|
+
expect { Chair.destroy(1) }.to raise_exception(ActiveRecord::Tableless::NoDatabase)
|
62
84
|
end
|
63
85
|
end
|
64
86
|
describe "#destroy_all" do
|
65
87
|
it "raises ActiveRecord::Tableless::NoDatabase" do
|
66
|
-
expect {
|
88
|
+
expect { Chair.destroy_all }.to raise_exception(ActiveRecord::Tableless::NoDatabase)
|
67
89
|
end
|
68
90
|
end
|
69
91
|
end
|
@@ -96,25 +118,25 @@ shared_examples_for "a succeeding database" do
|
|
96
118
|
if ActiveRecord::VERSION::STRING < "3.0"
|
97
119
|
describe "#find" do
|
98
120
|
it "raises ActiveRecord::RecordNotFound" do
|
99
|
-
expect {
|
121
|
+
expect { Chair.find(314) }.to raise_exception(ActiveRecord::RecordNotFound)
|
100
122
|
end
|
101
123
|
end
|
102
124
|
describe "#find(:all)" do
|
103
|
-
specify {
|
125
|
+
specify { Chair.find(:all) == []}
|
104
126
|
end
|
105
127
|
else ## ActiveRecord::VERSION::STRING >= "3.0"
|
106
128
|
describe "#all" do
|
107
|
-
specify {
|
129
|
+
specify { Chair.all == []}
|
108
130
|
end
|
109
131
|
end
|
110
132
|
describe "#create" do
|
111
|
-
specify {
|
133
|
+
specify { Chair.create(:name => 'Jarl') == true }
|
112
134
|
end
|
113
135
|
describe "#destroy" do
|
114
|
-
specify {
|
136
|
+
specify { Chair.destroy(1) == true }
|
115
137
|
end
|
116
138
|
describe "#destroy_all" do
|
117
|
-
specify {
|
139
|
+
specify { Chair.destroy_all == true }
|
118
140
|
end
|
119
141
|
end
|
120
142
|
|
@@ -141,20 +163,23 @@ describe "Active record with real database" do
|
|
141
163
|
ActiveRecord::Base.connection.execute("drop table if exists chairs")
|
142
164
|
ActiveRecord::Base.connection.execute("create table chairs (id INTEGER PRIMARY KEY, name TEXT )")
|
143
165
|
|
144
|
-
Object.send(:remove_const, Chair) rescue nil
|
145
166
|
class Chair < ActiveRecord::Base
|
146
167
|
end
|
147
168
|
end
|
148
|
-
|
169
|
+
after(:all) do
|
170
|
+
remove_models
|
149
171
|
ActiveRecord::Base.clear_all_connections!
|
150
172
|
end
|
151
|
-
|
173
|
+
|
152
174
|
subject { Chair.new(:name => 'Jarl') }
|
175
|
+
it_behaves_like "an active record"
|
153
176
|
it_behaves_like "a succeeding database"
|
154
177
|
end
|
155
178
|
|
156
179
|
describe "Tableless with succeeding database" do
|
157
|
-
|
158
|
-
|
180
|
+
before(:all) { make_tableless_model(:pretend_success, nil) }
|
181
|
+
after(:all){ remove_models }
|
182
|
+
subject { Chair.new(:name => 'Jarl') }
|
183
|
+
it_behaves_like "an active record"
|
159
184
|
it_behaves_like "a succeeding database"
|
160
185
|
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.
|
4
|
+
version: 1.1.3
|
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-
|
14
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
segments:
|
220
220
|
- 0
|
221
|
-
hash:
|
221
|
+
hash: 1824871736398580322
|
222
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
223
|
none: false
|
224
224
|
requirements:
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
version: '0'
|
228
228
|
segments:
|
229
229
|
- 0
|
230
|
-
hash:
|
230
|
+
hash: 1824871736398580322
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
233
|
rubygems_version: 1.8.24
|