sequel_model 0.3.2 → 0.3.2.1
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 +4 -0
- data/Rakefile +1 -1
- data/lib/sequel_model/base.rb +17 -4
- data/spec/base_spec.rb +26 -0
- data/spec/model_spec.rb +1 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
=== 0.3.2.1 (2008-01-24)
|
2
|
+
|
3
|
+
* Fixed Model.dataset to correctly set the dataset if using implicit naming or inheriting the superclass dataset (thanks celldee).
|
4
|
+
|
1
5
|
=== 0.3.2 (2008-01-24)
|
2
6
|
|
3
7
|
* Added Model#update_with_params method with support for virtual attributes and auto-filtering of unrelated parameters, and changed Model.create_with_params to support virtual attributes (#128).
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ include FileUtils
|
|
9
9
|
# Configuration
|
10
10
|
##############################################################################
|
11
11
|
NAME = "sequel_model"
|
12
|
-
VERS = "0.3.2"
|
12
|
+
VERS = "0.3.2.1"
|
13
13
|
CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
|
14
14
|
RDOC_OPTS = [
|
15
15
|
"--quiet",
|
data/lib/sequel_model/base.rb
CHANGED
@@ -19,11 +19,24 @@ module Sequel
|
|
19
19
|
|
20
20
|
# Returns the dataset associated with the Model class.
|
21
21
|
def self.dataset
|
22
|
-
@dataset
|
23
|
-
|
24
|
-
|
22
|
+
unless @dataset
|
23
|
+
if ds = super_dataset
|
24
|
+
set_dataset(ds.clone_merge({}))
|
25
|
+
elsif !(n = name).empty?
|
26
|
+
set_dataset(db[n.underscore.pluralize.to_sym])
|
27
|
+
else
|
28
|
+
raise Error, "No dataset associated with #{self}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@dataset
|
25
32
|
end
|
26
33
|
|
34
|
+
# def self.dataset
|
35
|
+
# @dataset ||= super_dataset ||
|
36
|
+
# (!(n = name).empty? && db[n.underscore.pluralize.to_sym]) ||
|
37
|
+
# (raise Error, "No dataset associated with #{self}")
|
38
|
+
# end
|
39
|
+
|
27
40
|
def self.super_dataset # :nodoc:
|
28
41
|
superclass.dataset if (superclass != Sequel::Model) && superclass.respond_to?(:dataset)
|
29
42
|
end
|
@@ -32,7 +45,7 @@ module Sequel
|
|
32
45
|
#
|
33
46
|
# See Dataset#columns for more information.
|
34
47
|
def self.columns
|
35
|
-
@columns ||=
|
48
|
+
@columns ||= dataset.columns or
|
36
49
|
raise Error, "Could not fetch columns for #{self}"
|
37
50
|
end
|
38
51
|
|
data/spec/base_spec.rb
CHANGED
@@ -182,4 +182,30 @@ 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
|
+
end
|
186
|
+
|
187
|
+
describe "A model class with implicit table name" do
|
188
|
+
setup do
|
189
|
+
class Donkey < Sequel::Model
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
specify "should have a dataset associated with the model class" do
|
194
|
+
Donkey.dataset.model_classes.should == {nil => Donkey}
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "A model inheriting from a model" do
|
199
|
+
setup do
|
200
|
+
class Feline < Sequel::Model
|
201
|
+
end
|
202
|
+
|
203
|
+
class Leopard < Feline
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
specify "should have a dataset associated with itself" do
|
208
|
+
Feline.dataset.model_classes.should == {nil => Feline}
|
209
|
+
Leopard.dataset.model_classes.should == {nil => Leopard}
|
210
|
+
end
|
185
211
|
end
|
data/spec/model_spec.rb
CHANGED
@@ -247,7 +247,7 @@ describe Sequel::Model, "magic methods" do
|
|
247
247
|
|
248
248
|
it "should support count_by_xxx" do
|
249
249
|
@m.count_by_name.should be_a_kind_of(@c)
|
250
|
-
@m.count_by_name.sql.should == "SELECT name, count(
|
250
|
+
@m.count_by_name.sql.should == "SELECT name, count(*) AS count FROM items GROUP BY name ORDER BY count"
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should support filter_by_xxx" do
|