sequel_model 0.4.1 → 0.4.2
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 +8 -0
- data/Rakefile +1 -1
- data/lib/sequel_model/base.rb +10 -2
- data/lib/sequel_model/relations.rb +1 -1
- data/spec/base_spec.rb +31 -3
- data/spec/relations_spec.rb +13 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 0.4.2 (2008-02-29)
|
2
|
+
|
3
|
+
* Fixed one_to_many implicit key to work correctly for namespaced classes (#167).
|
4
|
+
|
5
|
+
* Fixed Model.db= to affect the underlying dataset (#183).
|
6
|
+
|
7
|
+
* Fixed Model.implicit_table_name to disregard namespaces.
|
8
|
+
|
1
9
|
=== 0.4.1 (2008-02-10)
|
2
10
|
|
3
11
|
* Implemented Model#inspect (#151).
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ include FileUtils
|
|
9
9
|
# Configuration
|
10
10
|
##############################################################################
|
11
11
|
NAME = "sequel_model"
|
12
|
-
VERS = "0.4.
|
12
|
+
VERS = "0.4.2"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
data/lib/sequel_model/base.rb
CHANGED
@@ -9,6 +9,9 @@ module Sequel
|
|
9
9
|
# Sets the database associated with the Model class.
|
10
10
|
def self.db=(db)
|
11
11
|
@db = db
|
12
|
+
if @dataset
|
13
|
+
set_dataset(db[table_name])
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
# Called when a database is opened in order to automatically associate the
|
@@ -16,14 +19,19 @@ module Sequel
|
|
16
19
|
def self.database_opened(db)
|
17
20
|
@db = db if (self == Model) && !@db
|
18
21
|
end
|
22
|
+
|
23
|
+
# Returns the implicit table name for the model class.
|
24
|
+
def self.implicit_table_name
|
25
|
+
name.demodulize.underscore.pluralize.to_sym
|
26
|
+
end
|
19
27
|
|
20
28
|
# Returns the dataset associated with the Model class.
|
21
29
|
def self.dataset
|
22
30
|
unless @dataset
|
23
31
|
if ds = super_dataset
|
24
32
|
set_dataset(ds.clone)
|
25
|
-
elsif !
|
26
|
-
set_dataset(db[
|
33
|
+
elsif !name.empty?
|
34
|
+
set_dataset(db[implicit_table_name])
|
27
35
|
else
|
28
36
|
raise Error, "No dataset associated with #{self}"
|
29
37
|
end
|
@@ -76,7 +76,7 @@ module Sequel
|
|
76
76
|
def self.one_to_many(name, opts)
|
77
77
|
from = opts[:from]
|
78
78
|
from || (raise Error, "No association source defined (use :from option)")
|
79
|
-
key = opts[:key] || (self.to_s + ID_POSTFIX).to_sym
|
79
|
+
key = opts[:key] || (self.name.demodulize.underscore.to_s + ID_POSTFIX).to_sym
|
80
80
|
|
81
81
|
case from
|
82
82
|
when Symbol
|
data/spec/base_spec.rb
CHANGED
@@ -80,8 +80,8 @@ describe "Model#serialize" do
|
|
80
80
|
@c.create(:abc => "hello")
|
81
81
|
|
82
82
|
MODEL_DB.sqls.should == [ \
|
83
|
-
"INSERT INTO items (abc) VALUES ('
|
84
|
-
"INSERT INTO items (abc) VALUES ('\
|
83
|
+
"INSERT INTO items (abc) VALUES ('BAhpBg==\n')", \
|
84
|
+
"INSERT INTO items (abc) VALUES ('BAgiCmhlbGxv\n')", \
|
85
85
|
]
|
86
86
|
end
|
87
87
|
|
@@ -182,6 +182,15 @@ describe Sequel::Model, "dataset" do
|
|
182
182
|
specify "should raise if no dataset is explicitly set and the class is anonymous" do
|
183
183
|
proc {@b.dataset}.should raise_error(Sequel::Error)
|
184
184
|
end
|
185
|
+
|
186
|
+
specify "should disregard namespaces for the table name" do
|
187
|
+
module BlahBlah
|
188
|
+
class MwaHaHa < Sequel::Model
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
BlahBlah::MwaHaHa.dataset.sql.should == 'SELECT * FROM mwa_ha_has'
|
193
|
+
end
|
185
194
|
end
|
186
195
|
|
187
196
|
describe "A model class with implicit table name" do
|
@@ -208,4 +217,23 @@ describe "A model inheriting from a model" do
|
|
208
217
|
Feline.dataset.model_classes.should == {nil => Feline}
|
209
218
|
Leopard.dataset.model_classes.should == {nil => Leopard}
|
210
219
|
end
|
211
|
-
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "Model.db=" do
|
223
|
+
setup do
|
224
|
+
$db1 = Sequel::Database.new
|
225
|
+
$db2 = Sequel::Database.new
|
226
|
+
|
227
|
+
class BlueBlue < Sequel::Model
|
228
|
+
set_dataset $db1[:blue]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
specify "should affect the underlying dataset" do
|
233
|
+
BlueBlue.db = $db2
|
234
|
+
|
235
|
+
BlueBlue.dataset.db.should === $db2
|
236
|
+
BlueBlue.dataset.db.should_not === $db1
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
data/spec/relations_spec.rb
CHANGED
@@ -133,4 +133,17 @@ describe Sequel::Model, "one_to_many" do
|
|
133
133
|
a.should be_a_kind_of(Sequel::Dataset)
|
134
134
|
a.sql.should == 'SELECT * FROM abc WHERE (node_id = 1234)'
|
135
135
|
end
|
136
|
+
|
137
|
+
it "should support implicit key names" do
|
138
|
+
module Music
|
139
|
+
class BlueNote < Sequel::Model
|
140
|
+
one_to_many :attributes, :from => :abc
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
n = Music::BlueNote.new(:id => 1234)
|
145
|
+
a = n.attributes
|
146
|
+
a.should be_a_kind_of(Sequel::Dataset)
|
147
|
+
a.sql.should == 'SELECT * FROM abc WHERE (blue_note_id = 1234)'
|
148
|
+
end
|
136
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-29 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|