sequel 3.12.1 → 3.13.0
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 +42 -0
- data/README.rdoc +137 -118
- data/Rakefile +21 -66
- data/doc/active_record.rdoc +9 -9
- data/doc/advanced_associations.rdoc +59 -188
- data/doc/association_basics.rdoc +15 -2
- data/doc/cheat_sheet.rdoc +38 -33
- data/doc/dataset_filtering.rdoc +16 -7
- data/doc/prepared_statements.rdoc +7 -7
- data/doc/querying.rdoc +5 -4
- data/doc/release_notes/3.13.0.txt +210 -0
- data/doc/sharding.rdoc +1 -1
- data/doc/sql.rdoc +5 -5
- data/doc/validations.rdoc +11 -11
- data/lib/sequel/adapters/ado.rb +1 -1
- data/lib/sequel/adapters/do.rb +3 -3
- data/lib/sequel/adapters/firebird.rb +3 -3
- data/lib/sequel/adapters/jdbc/h2.rb +39 -0
- data/lib/sequel/adapters/jdbc/mysql.rb +5 -0
- data/lib/sequel/adapters/jdbc/oracle.rb +3 -3
- data/lib/sequel/adapters/mysql.rb +7 -4
- data/lib/sequel/adapters/oracle.rb +3 -3
- data/lib/sequel/adapters/shared/mssql.rb +10 -1
- data/lib/sequel/adapters/shared/mysql.rb +63 -0
- data/lib/sequel/adapters/shared/postgres.rb +61 -3
- data/lib/sequel/adapters/sqlite.rb +105 -18
- data/lib/sequel/connection_pool.rb +31 -30
- data/lib/sequel/core.rb +58 -58
- data/lib/sequel/core_sql.rb +52 -43
- data/lib/sequel/database/misc.rb +11 -0
- data/lib/sequel/database/query.rb +55 -17
- data/lib/sequel/dataset/actions.rb +2 -1
- data/lib/sequel/dataset/query.rb +2 -3
- data/lib/sequel/dataset/sql.rb +24 -11
- data/lib/sequel/extensions/schema_dumper.rb +1 -1
- data/lib/sequel/metaprogramming.rb +4 -0
- data/lib/sequel/model.rb +37 -19
- data/lib/sequel/model/associations.rb +33 -25
- data/lib/sequel/model/base.rb +2 -2
- data/lib/sequel/model/plugins.rb +7 -2
- data/lib/sequel/plugins/active_model.rb +1 -1
- data/lib/sequel/plugins/association_pks.rb +2 -2
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/boolean_readers.rb +2 -2
- data/lib/sequel/plugins/class_table_inheritance.rb +10 -2
- data/lib/sequel/plugins/identity_map.rb +3 -3
- data/lib/sequel/plugins/instance_hooks.rb +1 -1
- data/lib/sequel/plugins/json_serializer.rb +212 -0
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/list.rb +174 -0
- data/lib/sequel/plugins/many_through_many.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +6 -7
- data/lib/sequel/plugins/tree.rb +118 -0
- data/lib/sequel/plugins/xml_serializer.rb +321 -0
- data/lib/sequel/sql.rb +315 -206
- data/lib/sequel/timezones.rb +40 -17
- data/lib/sequel/version.rb +8 -2
- data/spec/adapters/firebird_spec.rb +2 -2
- data/spec/adapters/informix_spec.rb +1 -1
- data/spec/adapters/mssql_spec.rb +2 -2
- data/spec/adapters/mysql_spec.rb +2 -2
- data/spec/adapters/oracle_spec.rb +1 -1
- data/spec/adapters/postgres_spec.rb +36 -6
- data/spec/adapters/spec_helper.rb +2 -2
- data/spec/adapters/sqlite_spec.rb +1 -1
- data/spec/core/connection_pool_spec.rb +3 -3
- data/spec/core/core_sql_spec.rb +31 -13
- data/spec/core/database_spec.rb +39 -2
- data/spec/core/dataset_spec.rb +24 -12
- data/spec/core/expression_filters_spec.rb +5 -1
- data/spec/core/object_graph_spec.rb +1 -1
- data/spec/core/schema_generator_spec.rb +1 -1
- data/spec/core/schema_spec.rb +1 -1
- data/spec/core/spec_helper.rb +1 -1
- data/spec/core/version_spec.rb +1 -1
- data/spec/extensions/active_model_spec.rb +82 -67
- data/spec/extensions/association_dependencies_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +1 -1
- data/spec/extensions/association_proxies_spec.rb +1 -1
- data/spec/extensions/blank_spec.rb +1 -1
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/caching_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +3 -2
- data/spec/extensions/composition_spec.rb +2 -5
- data/spec/extensions/force_encoding_spec.rb +3 -1
- data/spec/extensions/hook_class_methods_spec.rb +1 -1
- data/spec/extensions/identity_map_spec.rb +1 -1
- data/spec/extensions/inflector_spec.rb +1 -1
- data/spec/extensions/instance_filters_spec.rb +1 -1
- data/spec/extensions/instance_hooks_spec.rb +1 -1
- data/spec/extensions/json_serializer_spec.rb +154 -0
- data/spec/extensions/lazy_attributes_spec.rb +1 -2
- data/spec/extensions/list_spec.rb +251 -0
- data/spec/extensions/looser_typecasting_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +3 -3
- data/spec/extensions/migration_spec.rb +1 -1
- data/spec/extensions/named_timezones_spec.rb +5 -6
- data/spec/extensions/nested_attributes_spec.rb +1 -1
- data/spec/extensions/optimistic_locking_spec.rb +1 -1
- data/spec/extensions/pagination_spec.rb +1 -1
- data/spec/extensions/pretty_table_spec.rb +1 -1
- data/spec/extensions/query_spec.rb +1 -1
- data/spec/extensions/rcte_tree_spec.rb +1 -1
- data/spec/extensions/schema_dumper_spec.rb +3 -2
- data/spec/extensions/schema_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +6 -2
- data/spec/extensions/sharding_spec.rb +1 -1
- data/spec/extensions/single_table_inheritance_spec.rb +1 -1
- data/spec/extensions/skip_create_refresh_spec.rb +1 -1
- data/spec/extensions/spec_helper.rb +7 -3
- data/spec/extensions/sql_expr_spec.rb +1 -1
- data/spec/extensions/string_date_time_spec.rb +1 -1
- data/spec/extensions/string_stripper_spec.rb +1 -1
- data/spec/extensions/subclasses_spec.rb +1 -1
- data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
- data/spec/extensions/thread_local_timezones_spec.rb +1 -1
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +1 -1
- data/spec/extensions/tree_spec.rb +119 -0
- data/spec/extensions/typecast_on_load_spec.rb +1 -1
- data/spec/extensions/update_primary_key_spec.rb +1 -1
- data/spec/extensions/validation_class_methods_spec.rb +1 -1
- data/spec/extensions/validation_helpers_spec.rb +1 -1
- data/spec/extensions/xml_serializer_spec.rb +142 -0
- data/spec/integration/associations_test.rb +1 -1
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +29 -14
- data/spec/integration/eager_loader_test.rb +1 -1
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +1 -1
- data/spec/integration/plugin_test.rb +316 -1
- data/spec/integration/prepared_statement_test.rb +1 -1
- data/spec/integration/schema_test.rb +8 -8
- data/spec/integration/spec_helper.rb +1 -1
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +35 -20
- data/spec/integration/type_test.rb +1 -1
- data/spec/model/association_reflection_spec.rb +1 -1
- data/spec/model/associations_spec.rb +49 -34
- data/spec/model/base_spec.rb +1 -1
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +1 -1
- data/spec/model/hooks_spec.rb +1 -1
- data/spec/model/inflector_spec.rb +1 -1
- data/spec/model/model_spec.rb +7 -1
- data/spec/model/plugins_spec.rb +1 -1
- data/spec/model/record_spec.rb +1 -3
- data/spec/model/spec_helper.rb +2 -2
- data/spec/model/validations_spec.rb +1 -1
- metadata +29 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
|
3
3
|
describe "Sequel::Plugins::LazyAttributes" do
|
|
4
4
|
before do
|
|
@@ -24,7 +24,6 @@ describe "Sequel::Plugins::LazyAttributes" do
|
|
|
24
24
|
end
|
|
25
25
|
else
|
|
26
26
|
i = where.args.last
|
|
27
|
-
i = i.instance_variable_get(:@array) if i.is_a?(Sequel::SQL::SQLArray)
|
|
28
27
|
Array(i).each do |x|
|
|
29
28
|
if sql =~ /SELECT name FROM/
|
|
30
29
|
yield(block[:name=>x.to_s])
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), '/spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "List plugin" do
|
|
4
|
+
def klass(opts={})
|
|
5
|
+
@db = MODEL_DB
|
|
6
|
+
c = Class.new(Sequel::Model(@db[:items]))
|
|
7
|
+
c.class_eval do
|
|
8
|
+
columns :id, :position, :scope_id, :pos
|
|
9
|
+
plugin :list, opts
|
|
10
|
+
self.use_transactions = false
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
attr_accessor :rows
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def checked_transaction(opts={})
|
|
17
|
+
return super if @in_transaction || !use_transaction?(opts)
|
|
18
|
+
@in_transaction = true
|
|
19
|
+
db.execute 'BEGIN'
|
|
20
|
+
super
|
|
21
|
+
db.execute 'COMMIT'
|
|
22
|
+
@in_transaction = false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
c
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def y(c, *hs)
|
|
29
|
+
c.rows = hs
|
|
30
|
+
ds = c.dataset
|
|
31
|
+
def ds.fetch_rows(sql)
|
|
32
|
+
db.execute(sql)
|
|
33
|
+
yield model.rows.shift
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
before do
|
|
38
|
+
@c = klass
|
|
39
|
+
@o = @c.load(:id=>7, :position=>3)
|
|
40
|
+
@sc = klass(:scope=>:scope_id)
|
|
41
|
+
@so = @sc.load(:id=>7, :position=>3, :scope_id=>5)
|
|
42
|
+
@db.reset
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should default to using :position as the position field" do
|
|
46
|
+
@c.position_field.should == :position
|
|
47
|
+
@c.new.list_dataset.sql.should == 'SELECT * FROM items ORDER BY position'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should accept a :field option to modify the position field" do
|
|
51
|
+
klass(:field=>:pos).position_field.should == :pos
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should accept a :scope option with a symbol for a single scope column" do
|
|
55
|
+
@sc.new(:scope_id=>4).list_dataset.sql.should == 'SELECT * FROM items WHERE (scope_id = 4) ORDER BY scope_id, position'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should accept a :scope option with an array of symbols for multiple scope columns" do
|
|
59
|
+
['SELECT * FROM items WHERE ((scope_id = 4) AND (pos = 3)) ORDER BY scope_id, pos, position',
|
|
60
|
+
'SELECT * FROM items WHERE ((pos = 3) AND (scope_id = 4)) ORDER BY scope_id, pos, position'].
|
|
61
|
+
should include(klass(:scope=>[:scope_id, :pos]).new(:scope_id=>4, :pos=>3).list_dataset.sql)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should accept a :scope option with a proc for a custom list scope" do
|
|
65
|
+
klass(:scope=>proc{|o| o.model.dataset.filter(:active).filter(:scope_id=>o.scope_id)}).new(:scope_id=>4).list_dataset.sql.should == 'SELECT * FROM items WHERE (active AND (scope_id = 4)) ORDER BY position'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should modify the order when using the plugin" do
|
|
69
|
+
c = Class.new(Sequel::Model(:items))
|
|
70
|
+
c.model.dataset.sql.should == 'SELECT * FROM items'
|
|
71
|
+
c.plugin :list
|
|
72
|
+
c.model.dataset.sql.should == 'SELECT * FROM items ORDER BY position'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should be able to access the position field as a class attribute" do
|
|
76
|
+
@c.position_field.should == :position
|
|
77
|
+
klass(:field=>:pos).position_field.should == :pos
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should be able to access the scope proc as a class attribute" do
|
|
81
|
+
@c.scope_proc.should == nil
|
|
82
|
+
@sc.scope_proc[@sc.new(:scope_id=>4)].sql.should == 'SELECT * FROM items WHERE (scope_id = 4) ORDER BY scope_id, position'
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should work correctly in subclasses" do
|
|
86
|
+
c = Class.new(klass(:scope=>:scope_id))
|
|
87
|
+
c.position_field.should == :position
|
|
88
|
+
c.scope_proc[c.new(:scope_id=>4)].sql.should == 'SELECT * FROM items WHERE (scope_id = 4) ORDER BY scope_id, position'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should have at_position return the model object at the given position" do
|
|
92
|
+
y(@c, :id=>1, :position=>1)
|
|
93
|
+
@o.at_position(10).should == @c.load(:id=>1, :position=>1)
|
|
94
|
+
y(@sc, :id=>2, :position=>2, :scope_id=>5)
|
|
95
|
+
@so.at_position(20).should == @sc.load(:id=>2, :position=>2, :scope_id=>5)
|
|
96
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 10) ORDER BY position LIMIT 1",
|
|
97
|
+
"SELECT * FROM items WHERE ((scope_id = 5) AND (position = 20)) ORDER BY scope_id, position LIMIT 1"]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should have last_position return the last position in the list" do
|
|
101
|
+
y(@c, :max=>10)
|
|
102
|
+
@o.last_position.should == 10
|
|
103
|
+
y(@sc, :max=>20)
|
|
104
|
+
@so.last_position.should == 20
|
|
105
|
+
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
106
|
+
"SELECT max(position) FROM items WHERE (scope_id = 5) LIMIT 1"]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should have list_dataset return the model's dataset for non scoped lists" do
|
|
110
|
+
@o.list_dataset.sql.should == 'SELECT * FROM items ORDER BY position'
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should have list dataset return a scoped dataset for scoped lists" do
|
|
114
|
+
@so.list_dataset.sql.should == 'SELECT * FROM items WHERE (scope_id = 5) ORDER BY scope_id, position'
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should have move_down without an argument move down a single position" do
|
|
118
|
+
y(@c, :max=>10)
|
|
119
|
+
@o.move_down.should == @o
|
|
120
|
+
@o.position.should == 4
|
|
121
|
+
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
122
|
+
"UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 4))",
|
|
123
|
+
"UPDATE items SET position = 4 WHERE (id = 7)"]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should have move_down with an argument move down the given number of positions" do
|
|
127
|
+
y(@c, :max=>10)
|
|
128
|
+
@o.move_down(3).should == @o
|
|
129
|
+
@o.position.should == 6
|
|
130
|
+
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
131
|
+
"UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 6))",
|
|
132
|
+
"UPDATE items SET position = 6 WHERE (id = 7)"]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should have move_down with a negative argument move up the given number of positions" do
|
|
136
|
+
@o.move_down(-1).should == @o
|
|
137
|
+
@o.position.should == 2
|
|
138
|
+
@db.sqls.should == ["UPDATE items SET position = (position + 1) WHERE ((position >= 2) AND (position < 3))",
|
|
139
|
+
"UPDATE items SET position = 2 WHERE (id = 7)"]
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "should have move_to raise an error if an invalid target is used" do
|
|
143
|
+
proc{@o.move_to(0)}.should raise_error(Sequel::Error)
|
|
144
|
+
y(@c, :max=>10)
|
|
145
|
+
proc{@o.move_to(11)}.should raise_error(Sequel::Error)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should have move_to use a transaction is the instance is configured to use transactions" do
|
|
149
|
+
@o.use_transactions = true
|
|
150
|
+
@o.move_to(2)
|
|
151
|
+
@db.sqls.should == ["BEGIN",
|
|
152
|
+
"UPDATE items SET position = (position + 1) WHERE ((position >= 2) AND (position < 3))",
|
|
153
|
+
"UPDATE items SET position = 2 WHERE (id = 7)",
|
|
154
|
+
"COMMIT"]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "should have move_to do nothing if the target position is the same as the current position" do
|
|
158
|
+
@o.use_transactions = true
|
|
159
|
+
@o.move_to(@o.position).should == @o
|
|
160
|
+
@o.position.should == 3
|
|
161
|
+
@db.sqls.should == []
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "should have move to shift entries correctly between current and target if moving up" do
|
|
165
|
+
@o.move_to(2)
|
|
166
|
+
@db.sqls.first.should == "UPDATE items SET position = (position + 1) WHERE ((position >= 2) AND (position < 3))"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "should have move to shift entries correctly between current and target if moving down" do
|
|
170
|
+
y(@c, :max=>10)
|
|
171
|
+
@o.move_to(4)
|
|
172
|
+
@db.sqls[1].should == "UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 4))"
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "should have move_to_bottom move the item to the last position" do
|
|
176
|
+
y(@c, :max=>10)
|
|
177
|
+
@o.move_to_bottom
|
|
178
|
+
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
179
|
+
"UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 10))",
|
|
180
|
+
"UPDATE items SET position = 10 WHERE (id = 7)"]
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should have move_to_top move the item to the first position" do
|
|
184
|
+
@o.move_to_top
|
|
185
|
+
@db.sqls.should == ["UPDATE items SET position = (position + 1) WHERE ((position >= 1) AND (position < 3))",
|
|
186
|
+
"UPDATE items SET position = 1 WHERE (id = 7)"]
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "should have move_up without an argument move up a single position" do
|
|
190
|
+
@o.move_up.should == @o
|
|
191
|
+
@o.position.should == 2
|
|
192
|
+
@db.sqls.should == ["UPDATE items SET position = (position + 1) WHERE ((position >= 2) AND (position < 3))",
|
|
193
|
+
"UPDATE items SET position = 2 WHERE (id = 7)"]
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "should have move_up with an argument move up the given number of positions" do
|
|
197
|
+
@o.move_up(2).should == @o
|
|
198
|
+
@o.position.should == 1
|
|
199
|
+
@db.sqls.should == ["UPDATE items SET position = (position + 1) WHERE ((position >= 1) AND (position < 3))",
|
|
200
|
+
"UPDATE items SET position = 1 WHERE (id = 7)"]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it "should have move_up with a negative argument move down the given number of positions" do
|
|
204
|
+
y(@c, :max=>10)
|
|
205
|
+
@o.move_up(-1).should == @o
|
|
206
|
+
@o.position.should == 4
|
|
207
|
+
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
208
|
+
"UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 4))",
|
|
209
|
+
"UPDATE items SET position = 4 WHERE (id = 7)"]
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "should have next return the next entry in the list if not given an argument" do
|
|
213
|
+
y(@c, :id=>9, :position=>4)
|
|
214
|
+
@o.next.should == @c.load(:id=>9, :position=>4)
|
|
215
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 4) ORDER BY position LIMIT 1"]
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it "should have next return the entry the given number of positions below the instance if given an argument" do
|
|
219
|
+
y(@c, :id=>9, :position=>5)
|
|
220
|
+
@o.next(2).should == @c.load(:id=>9, :position=>5)
|
|
221
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 5) ORDER BY position LIMIT 1"]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "should have next return a previous entry if given a negative argument" do
|
|
225
|
+
y(@c, :id=>9, :position=>2)
|
|
226
|
+
@o.next(-1).should == @c.load(:id=>9, :position=>2)
|
|
227
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 2) ORDER BY position LIMIT 1"]
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "should have position_value return the value of the position field" do
|
|
231
|
+
@o.position_value.should == 3
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it "should have prev return the previous entry in the list if not given an argument" do
|
|
235
|
+
y(@c, :id=>9, :position=>2)
|
|
236
|
+
@o.prev.should == @c.load(:id=>9, :position=>2)
|
|
237
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 2) ORDER BY position LIMIT 1"]
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "should have prev return the entry the given number of positions above the instance if given an argument" do
|
|
241
|
+
y(@c, :id=>9, :position=>1)
|
|
242
|
+
@o.prev(2).should == @c.load(:id=>9, :position=>1)
|
|
243
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 1) ORDER BY position LIMIT 1"]
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "should have prev return a following entry if given a negative argument" do
|
|
247
|
+
y(@c, :id=>9, :position=>4)
|
|
248
|
+
@o.prev(-1).should == @c.load(:id=>9, :position=>4)
|
|
249
|
+
@db.sqls.should == ["SELECT * FROM items WHERE (position = 4) ORDER BY position LIMIT 1"]
|
|
250
|
+
end
|
|
251
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
|
3
3
|
describe Sequel::Model, "many_through_many" do
|
|
4
4
|
before do
|
|
@@ -245,9 +245,9 @@ describe Sequel::Model, "many_through_many" do
|
|
|
245
245
|
h = []
|
|
246
246
|
@c1.many_through_many :tags, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_tags, :album_id, :tag_id]], :after_load=>:al
|
|
247
247
|
@c1.class_eval do
|
|
248
|
-
|
|
248
|
+
class_variable_set(:@@blah, h)
|
|
249
249
|
def al(v)
|
|
250
|
-
v.each{|x|
|
|
250
|
+
v.each{|x| self.class.send(:class_variable_get, :@@blah) << x.pk * 20}
|
|
251
251
|
end
|
|
252
252
|
end
|
|
253
253
|
@c2.class_eval do
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
4
|
require 'tzinfo'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
rescue LoadError => e
|
|
6
|
+
skip_warn "named_timezones_spec: can't load tzinfo (#{e.class}: #{e})"
|
|
7
|
+
else
|
|
9
8
|
Sequel.extension :named_timezones
|
|
10
9
|
Sequel.datetime_class = Time
|
|
11
10
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "Sequel::Schema::Generator dump methods" do
|
|
4
4
|
before do
|
|
@@ -291,7 +291,7 @@ END_MIG
|
|
|
291
291
|
["double precision", "timestamp with time zone", "timestamp without time zone",
|
|
292
292
|
"time with time zone", "time without time zone", "character varying(20)"] +
|
|
293
293
|
%w"nvarchar ntext smalldatetime smallmoney binary varbinary nchar" +
|
|
294
|
-
["timestamp(6) without time zone", "timestamp(6) with time zone"]
|
|
294
|
+
["timestamp(6) without time zone", "timestamp(6) with time zone", "int(12) unsigned"]
|
|
295
295
|
@d.meta_def(:schema) do |t, *o|
|
|
296
296
|
i = 0
|
|
297
297
|
types.map{|x| [:"c#{i+=1}", {:db_type=>x, :allow_null=>true}]}
|
|
@@ -361,6 +361,7 @@ create_table(:x) do
|
|
|
361
361
|
String :c61, :fixed=>true
|
|
362
362
|
DateTime :c62, :size=>6
|
|
363
363
|
DateTime :c63, :size=>6
|
|
364
|
+
Integer :c64
|
|
364
365
|
end
|
|
365
366
|
END_MIG
|
|
366
367
|
@d.dump_table_schema(:x).should == table.chomp
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
|
3
|
+
begin
|
|
3
4
|
require 'yaml'
|
|
4
5
|
require 'json'
|
|
5
|
-
|
|
6
|
+
rescue LoadError => e
|
|
7
|
+
skip_warn "serialization plugin: can't load json (#{e.class}: #{e})"
|
|
8
|
+
else
|
|
6
9
|
describe "Serialization plugin" do
|
|
7
10
|
before do
|
|
8
11
|
@c = Class.new(Sequel::Model(:items)) do
|
|
@@ -207,3 +210,4 @@ describe "Serialization plugin" do
|
|
|
207
210
|
o.abc.should == 9
|
|
208
211
|
end
|
|
209
212
|
end
|
|
213
|
+
end
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
unless Object.const_defined?('Sequel')
|
|
3
|
-
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
|
|
3
|
+
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
|
4
4
|
require 'sequel/core'
|
|
5
5
|
end
|
|
6
6
|
unless Sequel.const_defined?('Model')
|
|
7
|
-
$:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
|
|
7
|
+
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
|
8
8
|
require 'sequel/model'
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
Sequel.extension(*%w'string_date_time inflector pagination query pretty_table blank migration schema_dumper looser_typecasting sql_expr thread_local_timezones')
|
|
12
12
|
{:hook_class_methods=>[], :schema=>[], :validation_class_methods=>[]}.each{|p, opts| Sequel::Model.plugin(p, *opts)}
|
|
13
13
|
|
|
14
|
+
def skip_warn(s)
|
|
15
|
+
warn "Skipping test of #{s}" if ENV["SKIPPED_TEST_WARN"]
|
|
16
|
+
end
|
|
17
|
+
|
|
14
18
|
class MockDataset < Sequel::Dataset
|
|
15
19
|
def insert(*args)
|
|
16
20
|
@db.execute insert_sql(*args)
|
|
@@ -74,7 +78,7 @@ end
|
|
|
74
78
|
class << Sequel::Model
|
|
75
79
|
alias orig_columns columns
|
|
76
80
|
def columns(*cols)
|
|
77
|
-
return if cols.empty?
|
|
81
|
+
return @columns if cols.empty?
|
|
78
82
|
define_method(:columns){cols}
|
|
79
83
|
@dataset.instance_variable_set(:@columns, cols) if @dataset
|
|
80
84
|
def_column_accessor(*cols)
|