sequel 3.21.0 → 3.32.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 +539 -3
- data/MIT-LICENSE +1 -1
- data/README.rdoc +20 -6
- data/Rakefile +37 -19
- data/bin/sequel +1 -5
- data/doc/advanced_associations.rdoc +17 -0
- data/doc/association_basics.rdoc +293 -43
- data/doc/dataset_basics.rdoc +4 -4
- data/doc/dataset_filtering.rdoc +8 -0
- data/doc/mass_assignment.rdoc +54 -0
- data/doc/migration.rdoc +15 -538
- data/doc/model_hooks.rdoc +72 -27
- data/doc/opening_databases.rdoc +89 -50
- data/doc/prepared_statements.rdoc +40 -13
- data/doc/reflection.rdoc +8 -2
- data/doc/release_notes/3.22.0.txt +39 -0
- data/doc/release_notes/3.23.0.txt +172 -0
- data/doc/release_notes/3.24.0.txt +420 -0
- data/doc/release_notes/3.25.0.txt +88 -0
- data/doc/release_notes/3.26.0.txt +88 -0
- data/doc/release_notes/3.27.0.txt +82 -0
- data/doc/release_notes/3.28.0.txt +304 -0
- data/doc/release_notes/3.29.0.txt +459 -0
- data/doc/release_notes/3.30.0.txt +135 -0
- data/doc/release_notes/3.31.0.txt +146 -0
- data/doc/release_notes/3.32.0.txt +202 -0
- data/doc/schema_modification.rdoc +547 -0
- data/doc/sharding.rdoc +7 -1
- data/doc/testing.rdoc +129 -0
- data/doc/transactions.rdoc +137 -0
- data/doc/virtual_rows.rdoc +2 -2
- data/lib/sequel/adapters/ado/mssql.rb +18 -6
- data/lib/sequel/adapters/ado.rb +40 -18
- data/lib/sequel/adapters/amalgalite.rb +17 -9
- data/lib/sequel/adapters/db2.rb +175 -86
- data/lib/sequel/adapters/dbi.rb +15 -15
- data/lib/sequel/adapters/do/mysql.rb +5 -7
- data/lib/sequel/adapters/do/postgres.rb +0 -5
- data/lib/sequel/adapters/do/sqlite.rb +0 -5
- data/lib/sequel/adapters/do.rb +17 -36
- data/lib/sequel/adapters/firebird.rb +27 -208
- data/lib/sequel/adapters/ibmdb.rb +448 -0
- data/lib/sequel/adapters/informix.rb +6 -23
- data/lib/sequel/adapters/jdbc/as400.rb +16 -34
- data/lib/sequel/adapters/jdbc/db2.rb +52 -0
- data/lib/sequel/adapters/jdbc/derby.rb +260 -0
- data/lib/sequel/adapters/jdbc/firebird.rb +29 -0
- data/lib/sequel/adapters/jdbc/h2.rb +66 -30
- data/lib/sequel/adapters/jdbc/hsqldb.rb +177 -0
- data/lib/sequel/adapters/jdbc/informix.rb +26 -0
- data/lib/sequel/adapters/jdbc/jtds.rb +34 -0
- data/lib/sequel/adapters/jdbc/mssql.rb +3 -33
- data/lib/sequel/adapters/jdbc/mysql.rb +11 -11
- data/lib/sequel/adapters/jdbc/oracle.rb +88 -25
- data/lib/sequel/adapters/jdbc/postgresql.rb +9 -13
- data/lib/sequel/adapters/jdbc/sqlite.rb +2 -6
- data/lib/sequel/adapters/jdbc/sqlserver.rb +71 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +83 -0
- data/lib/sequel/adapters/jdbc.rb +231 -78
- data/lib/sequel/adapters/mock.rb +339 -0
- data/lib/sequel/adapters/mysql.rb +85 -184
- data/lib/sequel/adapters/mysql2.rb +26 -25
- data/lib/sequel/adapters/odbc/db2.rb +17 -0
- data/lib/sequel/adapters/odbc/mssql.rb +1 -6
- data/lib/sequel/adapters/odbc.rb +28 -9
- data/lib/sequel/adapters/openbase.rb +3 -5
- data/lib/sequel/adapters/oracle.rb +355 -53
- data/lib/sequel/adapters/postgres.rb +194 -33
- data/lib/sequel/adapters/shared/access.rb +32 -9
- data/lib/sequel/adapters/shared/db2.rb +328 -0
- data/lib/sequel/adapters/shared/firebird.rb +221 -0
- data/lib/sequel/adapters/shared/informix.rb +53 -0
- data/lib/sequel/adapters/shared/mssql.rb +278 -107
- data/lib/sequel/adapters/shared/mysql.rb +203 -65
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +149 -0
- data/lib/sequel/adapters/shared/oracle.rb +237 -46
- data/lib/sequel/adapters/shared/postgres.rb +214 -82
- data/lib/sequel/adapters/shared/progress.rb +5 -8
- data/lib/sequel/adapters/shared/sqlite.rb +200 -50
- data/lib/sequel/adapters/sqlite.rb +29 -21
- data/lib/sequel/adapters/swift/mysql.rb +12 -7
- data/lib/sequel/adapters/swift/postgres.rb +0 -5
- data/lib/sequel/adapters/swift/sqlite.rb +8 -6
- data/lib/sequel/adapters/swift.rb +5 -5
- data/lib/sequel/adapters/tinytds.rb +160 -19
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +66 -0
- data/lib/sequel/adapters/utils/stored_procedures.rb +1 -11
- data/lib/sequel/ast_transformer.rb +190 -0
- data/lib/sequel/connection_pool/threaded.rb +3 -2
- data/lib/sequel/connection_pool.rb +1 -1
- data/lib/sequel/core.rb +68 -5
- data/lib/sequel/database/connecting.rb +5 -6
- data/lib/sequel/database/dataset.rb +4 -4
- data/lib/sequel/database/dataset_defaults.rb +59 -1
- data/lib/sequel/database/logging.rb +1 -1
- data/lib/sequel/database/misc.rb +104 -19
- data/lib/sequel/database/query.rb +163 -59
- data/lib/sequel/database/schema_generator.rb +17 -7
- data/lib/sequel/database/schema_methods.rb +59 -29
- data/lib/sequel/dataset/actions.rb +240 -76
- data/lib/sequel/dataset/features.rb +91 -8
- data/lib/sequel/dataset/graph.rb +38 -11
- data/lib/sequel/dataset/misc.rb +50 -23
- data/lib/sequel/dataset/mutation.rb +12 -7
- data/lib/sequel/dataset/prepared_statements.rb +59 -27
- data/lib/sequel/dataset/query.rb +236 -43
- data/lib/sequel/dataset/sql.rb +676 -267
- data/lib/sequel/dataset.rb +8 -0
- data/lib/sequel/exceptions.rb +4 -0
- data/lib/sequel/extensions/columns_introspection.rb +61 -0
- data/lib/sequel/extensions/migration.rb +6 -4
- data/lib/sequel/extensions/named_timezones.rb +5 -0
- data/lib/sequel/extensions/query.rb +1 -1
- data/lib/sequel/extensions/thread_local_timezones.rb +1 -1
- data/lib/sequel/extensions/to_dot.rb +95 -83
- data/lib/sequel/model/associations.rb +1081 -344
- data/lib/sequel/model/base.rb +420 -133
- data/lib/sequel/model/errors.rb +1 -1
- data/lib/sequel/model/exceptions.rb +5 -1
- data/lib/sequel/model.rb +20 -10
- data/lib/sequel/plugins/active_model.rb +13 -1
- data/lib/sequel/plugins/association_pks.rb +22 -4
- data/lib/sequel/plugins/class_table_inheritance.rb +4 -4
- data/lib/sequel/plugins/composition.rb +43 -10
- data/lib/sequel/plugins/dataset_associations.rb +100 -0
- data/lib/sequel/plugins/defaults_setter.rb +58 -0
- data/lib/sequel/plugins/force_encoding.rb +6 -6
- data/lib/sequel/plugins/identity_map.rb +114 -7
- data/lib/sequel/plugins/many_through_many.rb +68 -7
- data/lib/sequel/plugins/nested_attributes.rb +65 -10
- data/lib/sequel/plugins/prepared_statements.rb +151 -0
- data/lib/sequel/plugins/prepared_statements_associations.rb +84 -0
- data/lib/sequel/plugins/prepared_statements_safe.rb +82 -0
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +59 -0
- data/lib/sequel/plugins/rcte_tree.rb +29 -15
- data/lib/sequel/plugins/serialization.rb +98 -49
- data/lib/sequel/plugins/serialization_modification_detection.rb +63 -0
- data/lib/sequel/plugins/sharding.rb +21 -54
- data/lib/sequel/plugins/single_table_inheritance.rb +3 -1
- data/lib/sequel/plugins/typecast_on_load.rb +9 -12
- data/lib/sequel/plugins/update_primary_key.rb +2 -2
- data/lib/sequel/plugins/xml_serializer.rb +3 -3
- data/lib/sequel/sql.rb +109 -52
- data/lib/sequel/timezones.rb +57 -38
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +146 -0
- data/spec/adapters/mssql_spec.rb +135 -30
- data/spec/adapters/mysql_spec.rb +244 -212
- data/spec/adapters/oracle_spec.rb +67 -77
- data/spec/adapters/postgres_spec.rb +267 -78
- data/spec/adapters/spec_helper.rb +6 -5
- data/spec/adapters/sqlite_spec.rb +35 -21
- data/spec/core/connection_pool_spec.rb +71 -92
- data/spec/core/core_sql_spec.rb +21 -30
- data/spec/core/database_spec.rb +789 -512
- data/spec/core/dataset_spec.rb +1176 -1061
- data/spec/core/expression_filters_spec.rb +159 -42
- data/spec/core/mock_adapter_spec.rb +419 -0
- data/spec/core/object_graph_spec.rb +86 -114
- data/spec/core/schema_generator_spec.rb +3 -3
- data/spec/core/schema_spec.rb +298 -38
- data/spec/core/spec_helper.rb +6 -48
- data/spec/extensions/active_model_spec.rb +13 -0
- data/spec/extensions/association_autoreloading_spec.rb +1 -10
- data/spec/extensions/association_dependencies_spec.rb +2 -12
- data/spec/extensions/association_pks_spec.rb +66 -32
- data/spec/extensions/caching_spec.rb +23 -50
- data/spec/extensions/class_table_inheritance_spec.rb +31 -83
- data/spec/extensions/columns_introspection_spec.rb +91 -0
- data/spec/extensions/composition_spec.rb +18 -13
- data/spec/extensions/dataset_associations_spec.rb +199 -0
- data/spec/extensions/defaults_setter_spec.rb +64 -0
- data/spec/extensions/hook_class_methods_spec.rb +65 -91
- data/spec/extensions/identity_map_spec.rb +114 -22
- data/spec/extensions/instance_filters_spec.rb +11 -21
- data/spec/extensions/instance_hooks_spec.rb +53 -0
- data/spec/extensions/json_serializer_spec.rb +4 -5
- data/spec/extensions/lazy_attributes_spec.rb +16 -20
- data/spec/extensions/list_spec.rb +17 -39
- data/spec/extensions/many_through_many_spec.rb +283 -250
- data/spec/extensions/migration_spec.rb +35 -32
- data/spec/extensions/named_timezones_spec.rb +23 -3
- data/spec/extensions/nested_attributes_spec.rb +97 -88
- data/spec/extensions/optimistic_locking_spec.rb +9 -20
- data/spec/extensions/prepared_statements_associations_spec.rb +111 -0
- data/spec/extensions/prepared_statements_safe_spec.rb +61 -0
- data/spec/extensions/prepared_statements_spec.rb +53 -0
- data/spec/extensions/prepared_statements_with_pk_spec.rb +31 -0
- data/spec/extensions/pretty_table_spec.rb +1 -6
- data/spec/extensions/query_spec.rb +6 -0
- data/spec/extensions/rcte_tree_spec.rb +41 -43
- data/spec/extensions/schema_dumper_spec.rb +5 -8
- data/spec/extensions/schema_spec.rb +13 -21
- data/spec/extensions/serialization_modification_detection_spec.rb +72 -0
- data/spec/extensions/serialization_spec.rb +81 -43
- data/spec/extensions/sharding_spec.rb +66 -140
- data/spec/extensions/single_table_inheritance_spec.rb +18 -29
- data/spec/extensions/spec_helper.rb +13 -61
- data/spec/extensions/sql_expr_spec.rb +20 -60
- data/spec/extensions/tactical_eager_loading_spec.rb +9 -19
- data/spec/extensions/thread_local_timezones_spec.rb +22 -2
- data/spec/extensions/timestamps_spec.rb +6 -6
- data/spec/extensions/to_dot_spec.rb +4 -7
- data/spec/extensions/touch_spec.rb +13 -14
- data/spec/extensions/tree_spec.rb +11 -26
- data/spec/extensions/typecast_on_load_spec.rb +1 -6
- data/spec/extensions/update_primary_key_spec.rb +30 -24
- data/spec/extensions/validation_class_methods_spec.rb +30 -51
- data/spec/extensions/validation_helpers_spec.rb +16 -35
- data/spec/extensions/xml_serializer_spec.rb +16 -4
- data/spec/integration/associations_test.rb +661 -21
- data/spec/integration/database_test.rb +4 -2
- data/spec/integration/dataset_test.rb +500 -67
- data/spec/integration/eager_loader_test.rb +19 -21
- data/spec/integration/model_test.rb +80 -1
- data/spec/integration/plugin_test.rb +367 -119
- data/spec/integration/prepared_statement_test.rb +222 -125
- data/spec/integration/schema_test.rb +217 -39
- data/spec/integration/spec_helper.rb +39 -30
- data/spec/integration/timezone_test.rb +38 -12
- data/spec/integration/transaction_test.rb +182 -5
- data/spec/integration/type_test.rb +17 -3
- data/spec/model/association_reflection_spec.rb +201 -7
- data/spec/model/associations_spec.rb +955 -662
- data/spec/model/base_spec.rb +275 -95
- data/spec/model/dataset_methods_spec.rb +7 -27
- data/spec/model/eager_loading_spec.rb +677 -676
- data/spec/model/hooks_spec.rb +349 -67
- data/spec/model/model_spec.rb +222 -168
- data/spec/model/plugins_spec.rb +24 -13
- data/spec/model/record_spec.rb +381 -218
- data/spec/model/spec_helper.rb +13 -71
- data/spec/model/validations_spec.rb +11 -0
- metadata +117 -73
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
|
+
require 'yaml'
|
|
2
3
|
|
|
3
4
|
describe "Sequel::Plugins::LazyAttributes" do
|
|
4
5
|
before do
|
|
5
|
-
@db =
|
|
6
|
+
@db = Sequel.mock
|
|
6
7
|
@db.meta_def(:schema){|*a| [[:id, {:type=>:integer}], [:name,{:type=>:string}]]}
|
|
7
8
|
class ::LazyAttributesModel < Sequel::Model(@db[:la])
|
|
8
9
|
plugin :lazy_attributes
|
|
@@ -10,27 +11,23 @@ describe "Sequel::Plugins::LazyAttributes" do
|
|
|
10
11
|
meta_def(:columns){[:id, :name]}
|
|
11
12
|
lazy_attributes :name
|
|
12
13
|
meta_def(:columns){[:id]}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
where = @opts[:where]
|
|
18
|
-
block = @mod_block || proc{|s| s}
|
|
19
|
-
if !where
|
|
20
|
-
if select.include?(:name)
|
|
21
|
-
yield(block[:id=>1, :name=>'1'])
|
|
22
|
-
yield(block[:id=>2, :name=>'2'])
|
|
14
|
+
dataset._fetch = proc do |sql|
|
|
15
|
+
if sql !~ /WHERE/
|
|
16
|
+
if sql =~ /name/
|
|
17
|
+
[{:id=>1, :name=>'1'}, {:id=>2, :name=>'2'}]
|
|
23
18
|
else
|
|
24
|
-
|
|
25
|
-
yield(:id=>2)
|
|
19
|
+
[{:id=>1}, {:id=>2}]
|
|
26
20
|
end
|
|
27
21
|
else
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
if sql =~ /id IN \(([\d, ]+)\)/
|
|
23
|
+
$1.split(', ')
|
|
24
|
+
elsif sql =~ /id = (\d)/
|
|
25
|
+
[$1]
|
|
26
|
+
end.map do |x|
|
|
30
27
|
if sql =~ /SELECT name FROM/
|
|
31
|
-
|
|
28
|
+
{:name=>x.to_s}
|
|
32
29
|
else
|
|
33
|
-
|
|
30
|
+
{:id=>x.to_i, :name=>x.to_s}
|
|
34
31
|
end
|
|
35
32
|
end
|
|
36
33
|
end
|
|
@@ -38,7 +35,7 @@ describe "Sequel::Plugins::LazyAttributes" do
|
|
|
38
35
|
end
|
|
39
36
|
@c = ::LazyAttributesModel
|
|
40
37
|
@ds = LazyAttributesModel.dataset
|
|
41
|
-
@db.
|
|
38
|
+
@db.sqls
|
|
42
39
|
end
|
|
43
40
|
after do
|
|
44
41
|
Object.send(:remove_const, :LazyAttributesModel)
|
|
@@ -136,7 +133,7 @@ describe "Sequel::Plugins::LazyAttributes" do
|
|
|
136
133
|
|
|
137
134
|
it "should work with the serialization plugin" do
|
|
138
135
|
@c.plugin :serialization, :yaml, :name
|
|
139
|
-
@ds.
|
|
136
|
+
@ds._fetch = [[{:id=>1}, {:id=>2}], [{:id=>1, :name=>"--- 3\n"}, {:id=>2, :name=>"--- 6\n"}], [{:id=>1}], [{:name=>"--- 3\n"}]]
|
|
140
137
|
@c.with_identity_map do
|
|
141
138
|
ms = @ds.all
|
|
142
139
|
ms.map{|m| m.values}.should == [{:id=>1}, {:id=>2}]
|
|
@@ -146,7 +143,6 @@ describe "Sequel::Plugins::LazyAttributes" do
|
|
|
146
143
|
ms.map{|m| m.name}.should == [3,6]
|
|
147
144
|
@db.sqls.should == ['SELECT id FROM la', 'SELECT id, name FROM la WHERE (id IN (1, 2))']
|
|
148
145
|
end
|
|
149
|
-
@db.reset
|
|
150
146
|
@c.with_identity_map do
|
|
151
147
|
m = @ds.first
|
|
152
148
|
m.values.should == {:id=>1}
|
|
@@ -8,32 +8,10 @@ describe "List plugin" do
|
|
|
8
8
|
columns :id, :position, :scope_id, :pos
|
|
9
9
|
plugin :list, opts
|
|
10
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
11
|
end
|
|
25
12
|
c
|
|
26
13
|
end
|
|
27
14
|
|
|
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
15
|
before do
|
|
38
16
|
@c = klass
|
|
39
17
|
@o = @c.load(:id=>7, :position=>3)
|
|
@@ -89,18 +67,18 @@ describe "List plugin" do
|
|
|
89
67
|
end
|
|
90
68
|
|
|
91
69
|
it "should have at_position return the model object at the given position" do
|
|
92
|
-
|
|
70
|
+
@c.dataset._fetch = {:id=>1, :position=>1}
|
|
93
71
|
@o.at_position(10).should == @c.load(:id=>1, :position=>1)
|
|
94
|
-
|
|
72
|
+
@sc.dataset._fetch = {:id=>2, :position=>2, :scope_id=>5}
|
|
95
73
|
@so.at_position(20).should == @sc.load(:id=>2, :position=>2, :scope_id=>5)
|
|
96
74
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 10) ORDER BY position LIMIT 1",
|
|
97
75
|
"SELECT * FROM items WHERE ((scope_id = 5) AND (position = 20)) ORDER BY scope_id, position LIMIT 1"]
|
|
98
76
|
end
|
|
99
77
|
|
|
100
78
|
it "should have last_position return the last position in the list" do
|
|
101
|
-
|
|
79
|
+
@c.dataset._fetch = {:max=>10}
|
|
102
80
|
@o.last_position.should == 10
|
|
103
|
-
|
|
81
|
+
@sc.dataset._fetch = {:max=>20}
|
|
104
82
|
@so.last_position.should == 20
|
|
105
83
|
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
106
84
|
"SELECT max(position) FROM items WHERE (scope_id = 5) LIMIT 1"]
|
|
@@ -115,7 +93,7 @@ describe "List plugin" do
|
|
|
115
93
|
end
|
|
116
94
|
|
|
117
95
|
it "should have move_down without an argument move down a single position" do
|
|
118
|
-
|
|
96
|
+
@c.dataset._fetch = {:max=>10}
|
|
119
97
|
@o.move_down.should == @o
|
|
120
98
|
@o.position.should == 4
|
|
121
99
|
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
@@ -124,7 +102,7 @@ describe "List plugin" do
|
|
|
124
102
|
end
|
|
125
103
|
|
|
126
104
|
it "should have move_down with an argument move down the given number of positions" do
|
|
127
|
-
|
|
105
|
+
@c.dataset._fetch = {:max=>10}
|
|
128
106
|
@o.move_down(3).should == @o
|
|
129
107
|
@o.position.should == 6
|
|
130
108
|
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
@@ -141,11 +119,11 @@ describe "List plugin" do
|
|
|
141
119
|
|
|
142
120
|
it "should have move_to raise an error if an invalid target is used" do
|
|
143
121
|
proc{@o.move_to(0)}.should raise_error(Sequel::Error)
|
|
144
|
-
|
|
122
|
+
@c.dataset._fetch = {:max=>10}
|
|
145
123
|
proc{@o.move_to(11)}.should raise_error(Sequel::Error)
|
|
146
124
|
end
|
|
147
125
|
|
|
148
|
-
it "should have move_to use a transaction
|
|
126
|
+
it "should have move_to use a transaction if the instance is configured to use transactions" do
|
|
149
127
|
@o.use_transactions = true
|
|
150
128
|
@o.move_to(2)
|
|
151
129
|
@db.sqls.should == ["BEGIN",
|
|
@@ -167,13 +145,13 @@ describe "List plugin" do
|
|
|
167
145
|
end
|
|
168
146
|
|
|
169
147
|
it "should have move to shift entries correctly between current and target if moving down" do
|
|
170
|
-
|
|
148
|
+
@c.dataset._fetch = {:max=>10}
|
|
171
149
|
@o.move_to(4)
|
|
172
150
|
@db.sqls[1].should == "UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 4))"
|
|
173
151
|
end
|
|
174
152
|
|
|
175
153
|
it "should have move_to_bottom move the item to the last position" do
|
|
176
|
-
|
|
154
|
+
@c.dataset._fetch = {:max=>10}
|
|
177
155
|
@o.move_to_bottom
|
|
178
156
|
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
179
157
|
"UPDATE items SET position = (position - 1) WHERE ((position >= 4) AND (position <= 10))",
|
|
@@ -201,7 +179,7 @@ describe "List plugin" do
|
|
|
201
179
|
end
|
|
202
180
|
|
|
203
181
|
it "should have move_up with a negative argument move down the given number of positions" do
|
|
204
|
-
|
|
182
|
+
@c.dataset._fetch = {:max=>10}
|
|
205
183
|
@o.move_up(-1).should == @o
|
|
206
184
|
@o.position.should == 4
|
|
207
185
|
@db.sqls.should == ["SELECT max(position) FROM items LIMIT 1",
|
|
@@ -210,19 +188,19 @@ describe "List plugin" do
|
|
|
210
188
|
end
|
|
211
189
|
|
|
212
190
|
it "should have next return the next entry in the list if not given an argument" do
|
|
213
|
-
|
|
191
|
+
@c.dataset._fetch = {:id=>9, :position=>4}
|
|
214
192
|
@o.next.should == @c.load(:id=>9, :position=>4)
|
|
215
193
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 4) ORDER BY position LIMIT 1"]
|
|
216
194
|
end
|
|
217
195
|
|
|
218
196
|
it "should have next return the entry the given number of positions below the instance if given an argument" do
|
|
219
|
-
|
|
197
|
+
@c.dataset._fetch = {:id=>9, :position=>5}
|
|
220
198
|
@o.next(2).should == @c.load(:id=>9, :position=>5)
|
|
221
199
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 5) ORDER BY position LIMIT 1"]
|
|
222
200
|
end
|
|
223
201
|
|
|
224
202
|
it "should have next return a previous entry if given a negative argument" do
|
|
225
|
-
|
|
203
|
+
@c.dataset._fetch = {:id=>9, :position=>2}
|
|
226
204
|
@o.next(-1).should == @c.load(:id=>9, :position=>2)
|
|
227
205
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 2) ORDER BY position LIMIT 1"]
|
|
228
206
|
end
|
|
@@ -232,19 +210,19 @@ describe "List plugin" do
|
|
|
232
210
|
end
|
|
233
211
|
|
|
234
212
|
it "should have prev return the previous entry in the list if not given an argument" do
|
|
235
|
-
|
|
213
|
+
@c.dataset._fetch = {:id=>9, :position=>2}
|
|
236
214
|
@o.prev.should == @c.load(:id=>9, :position=>2)
|
|
237
215
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 2) ORDER BY position LIMIT 1"]
|
|
238
216
|
end
|
|
239
217
|
|
|
240
218
|
it "should have prev return the entry the given number of positions above the instance if given an argument" do
|
|
241
|
-
|
|
219
|
+
@c.dataset._fetch = {:id=>9, :position=>1}
|
|
242
220
|
@o.prev(2).should == @c.load(:id=>9, :position=>1)
|
|
243
221
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 1) ORDER BY position LIMIT 1"]
|
|
244
222
|
end
|
|
245
223
|
|
|
246
224
|
it "should have prev return a following entry if given a negative argument" do
|
|
247
|
-
|
|
225
|
+
@c.dataset._fetch = {:id=>9, :position=>4}
|
|
248
226
|
@o.prev(-1).should == @c.load(:id=>9, :position=>4)
|
|
249
227
|
@db.sqls.should == ["SELECT * FROM items WHERE (position = 4) ORDER BY position LIMIT 1"]
|
|
250
228
|
end
|