sequel 3.48.0 → 4.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- data/spec/spec_config.rb.example +0 -10
|
@@ -67,12 +67,4 @@ describe "Sequel::Deprecated" do
|
|
|
67
67
|
@output.first.should == 'foo'
|
|
68
68
|
@output.count.should == 4
|
|
69
69
|
end
|
|
70
|
-
|
|
71
|
-
specify "should have deprecated_module return a module where all instance methods are marked deprecated" do
|
|
72
|
-
m = Module.new{def foo; 1 end}
|
|
73
|
-
dm = @d.deprecated_module(m){|meth| ["Module##{meth}", "Load the bar extension"]}
|
|
74
|
-
dm.should_not == m
|
|
75
|
-
c = Class.new{include dm}.new.foo.should == 1
|
|
76
|
-
@output.should == ['Module#foo is deprecated and will be removed in Sequel 4.0. Load the bar extension.']
|
|
77
|
-
end
|
|
78
70
|
end
|
|
@@ -748,6 +748,10 @@ describe "Sequel core extension replacements" do
|
|
|
748
748
|
Sequel.blob(o).should equal(o)
|
|
749
749
|
end
|
|
750
750
|
|
|
751
|
+
it "Sequel.deep_qualify should do a deep qualification into nested structors" do
|
|
752
|
+
l(Sequel.deep_qualify(:t, Sequel.+(:c, 1)), "(t.c + 1)")
|
|
753
|
+
end
|
|
754
|
+
|
|
751
755
|
it "Sequel.qualify should return a qualified identifier" do
|
|
752
756
|
l(Sequel.qualify(:t, :c), "t.c")
|
|
753
757
|
end
|
|
@@ -798,6 +802,8 @@ describe "Sequel core extension replacements" do
|
|
|
798
802
|
l(Sequel.subscript(:a, 1), 'a[1]')
|
|
799
803
|
l(Sequel.subscript(:a, 1, 2), 'a[1, 2]')
|
|
800
804
|
l(Sequel.subscript(:a, [1, 2]), 'a[1, 2]')
|
|
805
|
+
l(Sequel.subscript(:a, 1..2), 'a[1:2]')
|
|
806
|
+
l(Sequel.subscript(:a, 1...3), 'a[1:2]')
|
|
801
807
|
end
|
|
802
808
|
|
|
803
809
|
it "Sequel.function should return an SQL function" do
|
|
@@ -1010,20 +1016,32 @@ describe "Sequel.delay" do
|
|
|
1010
1016
|
end
|
|
1011
1017
|
end
|
|
1012
1018
|
|
|
1013
|
-
describe
|
|
1019
|
+
describe Sequel do
|
|
1014
1020
|
before do
|
|
1015
|
-
Sequel::JSON =
|
|
1016
|
-
|
|
1017
|
-
|
|
1021
|
+
Sequel::JSON = Class.new do
|
|
1022
|
+
self::ParserError = Sequel
|
|
1023
|
+
def self.parse(json, opts={})
|
|
1024
|
+
[json, opts]
|
|
1025
|
+
end
|
|
1018
1026
|
end
|
|
1019
1027
|
end
|
|
1020
1028
|
after do
|
|
1021
1029
|
Sequel.send(:remove_const, :JSON)
|
|
1022
1030
|
end
|
|
1023
1031
|
|
|
1024
|
-
specify "should parse json correctly" do
|
|
1032
|
+
specify ".parse_json should parse json correctly" do
|
|
1025
1033
|
Sequel.parse_json('[]').should == ['[]', {:create_additions=>false}]
|
|
1026
1034
|
end
|
|
1035
|
+
|
|
1036
|
+
specify ".json_parser_error_class should return the related parser error class" do
|
|
1037
|
+
Sequel.json_parser_error_class.should == Sequel
|
|
1038
|
+
end
|
|
1039
|
+
|
|
1040
|
+
specify ".object_to_json should return a json version of the object" do
|
|
1041
|
+
o = Object.new
|
|
1042
|
+
def o.to_json(*args); [1, args]; end
|
|
1043
|
+
Sequel.object_to_json(o, :foo).should == [1, [:foo]]
|
|
1044
|
+
end
|
|
1027
1045
|
end
|
|
1028
1046
|
|
|
1029
1047
|
describe "Sequel::LiteralString" do
|
|
@@ -172,6 +172,10 @@ describe Sequel::Dataset, " graphing" do
|
|
|
172
172
|
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :q]).add_graph_aliases(:y=>[:lines, :r]).sql.should == 'SELECT points.q AS x, lines.r AS y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
|
173
173
|
end
|
|
174
174
|
|
|
175
|
+
it "#add_graph_aliases should raise an error if called without existing graph aliases" do
|
|
176
|
+
proc{@ds1.add_graph_aliases(:y=>[:lines, :r])}.should raise_error(Sequel::Error)
|
|
177
|
+
end
|
|
178
|
+
|
|
175
179
|
it "#set_graph_aliases should allow a third entry to specify an expression to use other than the default" do
|
|
176
180
|
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x, 1], :y=>[:lines, :y, Sequel.function(:random)])
|
|
177
181
|
['SELECT 1 AS x, random() AS y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)',
|
|
@@ -205,74 +209,8 @@ describe Sequel::Dataset, " graphing" do
|
|
|
205
209
|
].should(include(ds.sql))
|
|
206
210
|
end
|
|
207
211
|
|
|
208
|
-
qspecify "#graph_each should split the result set into component tables" do
|
|
209
|
-
@db.fetch = [[{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}],
|
|
210
|
-
[{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>8, :name=>9, :graphs_x=>10, :graphs_y=>11, :graphs_lines_x=>12}],
|
|
211
|
-
[{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graph_id_0=>8, :graph_x=>9, :graph_y=>10, :graph_graph_id=>11}]]
|
|
212
|
-
|
|
213
|
-
@ds1.graph(@ds2, :x=>:id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}}]
|
|
214
|
-
@ds1.graph(@ds2, :x=>:id).graph(@ds3, :id=>:graph_id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graphs=>{:id=>8, :name=>9, :x=>10, :y=>11, :lines_x=>12}}]
|
|
215
|
-
@ds1.graph(@ds2, :x=>:id).graph(@ds2, {:y=>:points__id}, :table_alias=>:graph).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graph=>{:id=>8, :x=>9, :y=>10, :graph_id=>11}}]
|
|
216
|
-
end
|
|
217
|
-
|
|
218
212
|
it "#ungraphed should remove the splitting of result sets into component tables" do
|
|
219
213
|
@db.fetch = {:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}
|
|
220
214
|
@ds1.graph(@ds2, :x=>:id).ungraphed.all.should == [{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}]
|
|
221
215
|
end
|
|
222
|
-
|
|
223
|
-
qspecify "#graph_each should give a nil value instead of a hash when all values for a table are nil" do
|
|
224
|
-
@db.fetch = [[{:id=>1,:x=>2,:y=>3,:lines_id=>nil,:lines_x=>nil,:lines_y=>nil,:graph_id=>nil}],
|
|
225
|
-
[{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>nil, :name=>nil, :graphs_x=>nil, :graphs_y=>nil, :graphs_lines_x=>nil},
|
|
226
|
-
{:id=>2,:x=>4,:y=>5,:lines_id=>nil,:lines_x=>nil,:lines_y=>nil,:graph_id=>nil, :graphs_id=>nil, :name=>nil, :graphs_x=>nil, :graphs_y=>nil, :graphs_lines_x=>nil},
|
|
227
|
-
{:id=>3,:x=>5,:y=>6,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>7, :name=>8, :graphs_x=>9, :graphs_y=>10, :graphs_lines_x=>11},
|
|
228
|
-
{:id=>3,:x=>5,:y=>6,:lines_id=>7,:lines_x=>5,:lines_y=>8,:graph_id=>9, :graphs_id=>9, :name=>10, :graphs_x=>10, :graphs_y=>11, :graphs_lines_x=>12}]]
|
|
229
|
-
|
|
230
|
-
@ds1.graph(@ds2, :x=>:id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>nil}]
|
|
231
|
-
@ds1.graph(@ds2, :x=>:id).graph(@ds3, :id=>:graph_id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graphs=>nil},
|
|
232
|
-
{:points=>{:id=>2, :x=>4, :y=>5}, :lines=>nil, :graphs=>nil},
|
|
233
|
-
{:points=>{:id=>3, :x=>5, :y=>6}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graphs=>{:id=>7, :name=>8, :x=>9, :y=>10, :lines_x=>11}},
|
|
234
|
-
{:points=>{:id=>3, :x=>5, :y=>6}, :lines=>{:id=>7, :x=>5, :y=>8, :graph_id=>9}, :graphs=>{:id=>9, :name=>10, :x=>10, :y=>11, :lines_x=>12}}]
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
qspecify "#graph_each should not give a nil value instead of a hash when any value for a table is false" do
|
|
238
|
-
@db.fetch = {:id=>1,:x=>2,:y=>3,:lines_id=>nil,:lines_x=>false,:lines_y=>nil,:graph_id=>nil}
|
|
239
|
-
@ds1.graph(@ds2, :x=>:id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>nil, :x=>false, :y=>nil, :graph_id=>nil}}]
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
qspecify "#graph_each should not included tables graphed with the :select => false option in the result set" do
|
|
243
|
-
@db.fetch = {:id=>1,:x=>2,:y=>3,:graphs_id=>8, :name=>9, :graphs_x=>10, :graphs_y=>11, :lines_x=>12}
|
|
244
|
-
@ds1.graph(:lines, {:x=>:id}, :select=>false).graph(:graphs, :id=>:graph_id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :graphs=>{:id=>8, :name=>9, :x=>10, :y=>11, :lines_x=>12}}]
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
qspecify "#graph_each should only include the columns selected with #set_graph_aliases and #add_graph_aliases, if called" do
|
|
248
|
-
@db.fetch = [nil, [{:x=>2,:y=>3}], nil, [{:x=>2}], [{:x=>2, :q=>18}]]
|
|
249
|
-
|
|
250
|
-
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y]).all.should == [{:points=>{:x=>2}, :lines=>{:y=>3}}]
|
|
251
|
-
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x])
|
|
252
|
-
ds.all.should == [{:points=>{:x=>2}, :lines=>nil}]
|
|
253
|
-
ds = ds.add_graph_aliases(:q=>[:points, :r, 18])
|
|
254
|
-
ds.all.should == [{:points=>{:x=>2, :r=>18}, :lines=>nil}]
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
qspecify "#graph_each should correctly map values when #set_graph_aliases is used with a third argument for each entry" do
|
|
258
|
-
@db.fetch = [nil, {:x=>2,:y=>3}]
|
|
259
|
-
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :z1, 2], :y=>[:lines, :z2, Sequel.function(:random)]).all.should == [{:points=>{:z1=>2}, :lines=>{:z2=>3}}]
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
qspecify "#graph_each should correctly map values when #set_graph_aliases is used with a single argument for each entry" do
|
|
263
|
-
@db.fetch = [nil, {:x=>2,:y=>3}]
|
|
264
|
-
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points], :y=>[:lines]).all.should == [{:points=>{:x=>2}, :lines=>{:y=>3}}]
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
qspecify "#graph_each should correctly map values when #set_graph_aliases is used with a symbol for each entry" do
|
|
268
|
-
@db.fetch = [nil, {:x=>2,:y=>3}]
|
|
269
|
-
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>:points, :y=>:lines).all.should == [{:points=>{:x=>2}, :lines=>{:y=>3}}]
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
qspecify "#graph_each should run the row_proc for graphed datasets" do
|
|
273
|
-
@ds1.row_proc = proc{|h| h.keys.each{|k| h[k] *= 2}; h}
|
|
274
|
-
@ds2.row_proc = proc{|h| h.keys.each{|k| h[k] *= 3}; h}
|
|
275
|
-
@db.fetch = {:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}
|
|
276
|
-
@ds1.graph(@ds2, :x=>:id).all.should == [{:points=>{:id=>2, :x=>4, :y=>6}, :lines=>{:id=>12, :x=>15, :y=>18, :graph_id=>21}}]
|
|
277
|
-
end
|
|
278
216
|
end
|
data/spec/core/schema_spec.rb
CHANGED
|
@@ -502,11 +502,19 @@ describe "DB#create_table" do
|
|
|
502
502
|
specify "should accept unnamed constraint definitions with blocks" do
|
|
503
503
|
@db.create_table(:cats) do
|
|
504
504
|
integer :score
|
|
505
|
-
check{(x
|
|
505
|
+
check{(x > 0) & (y < 1)}
|
|
506
506
|
end
|
|
507
507
|
@db.sqls.should == ["CREATE TABLE cats (score integer, CHECK ((x > 0) AND (y < 1)))"]
|
|
508
508
|
end
|
|
509
509
|
|
|
510
|
+
specify "should accept unnamed constraint definitions with function calls" do
|
|
511
|
+
@db.create_table(:cats) do
|
|
512
|
+
integer :score
|
|
513
|
+
check{f(x)}
|
|
514
|
+
end
|
|
515
|
+
@db.sqls.should == ["CREATE TABLE cats (score integer, CHECK (f(x)))"]
|
|
516
|
+
end
|
|
517
|
+
|
|
510
518
|
specify "should accept unnamed constraint definitions" do
|
|
511
519
|
@db.create_table(:cats) do
|
|
512
520
|
check 'price < ?', 100
|
|
@@ -514,6 +522,13 @@ describe "DB#create_table" do
|
|
|
514
522
|
@db.sqls.should == ["CREATE TABLE cats (CHECK (price < 100))"]
|
|
515
523
|
end
|
|
516
524
|
|
|
525
|
+
specify "should accept arrays of pairs constraints" do
|
|
526
|
+
@db.create_table(:cats) do
|
|
527
|
+
check [[:price, 100]]
|
|
528
|
+
end
|
|
529
|
+
@db.sqls.should == ["CREATE TABLE cats (CHECK (price = 100))"]
|
|
530
|
+
end
|
|
531
|
+
|
|
517
532
|
specify "should accept hash constraints" do
|
|
518
533
|
@db.create_table(:cats) do
|
|
519
534
|
check :price=>100
|
|
@@ -521,6 +536,13 @@ describe "DB#create_table" do
|
|
|
521
536
|
@db.sqls.should == ["CREATE TABLE cats (CHECK (price = 100))"]
|
|
522
537
|
end
|
|
523
538
|
|
|
539
|
+
specify "should accept array constraints" do
|
|
540
|
+
@db.create_table(:cats) do
|
|
541
|
+
check [Sequel.expr(:x) > 0, Sequel.expr(:y) < 1]
|
|
542
|
+
end
|
|
543
|
+
@db.sqls.should == ["CREATE TABLE cats (CHECK ((x > 0) AND (y < 1)))"]
|
|
544
|
+
end
|
|
545
|
+
|
|
524
546
|
specify "should accept named constraint definitions" do
|
|
525
547
|
@db.create_table(:cats) do
|
|
526
548
|
integer :score
|
|
@@ -1124,14 +1146,6 @@ describe "Database#create_table" do
|
|
|
1124
1146
|
@db.sqls.should == ['CREATE TEMPORARY TABLE test_tmp (id integer NOT NULL PRIMARY KEY AUTOINCREMENT, name text)',
|
|
1125
1147
|
'CREATE UNIQUE INDEX test_tmp_name_index ON test_tmp (name)']
|
|
1126
1148
|
end
|
|
1127
|
-
|
|
1128
|
-
qspecify "should not use default schema when creating a temporary table" do
|
|
1129
|
-
@db.default_schema = :foo
|
|
1130
|
-
@db.create_table :test_tmp, :temp => true do
|
|
1131
|
-
column :name, :text
|
|
1132
|
-
end
|
|
1133
|
-
@db.sqls.should == ['CREATE TEMPORARY TABLE test_tmp (name text)']
|
|
1134
|
-
end
|
|
1135
1149
|
end
|
|
1136
1150
|
|
|
1137
1151
|
describe "Database#alter_table" do
|
|
@@ -1287,11 +1301,20 @@ describe "Database#create_view" do
|
|
|
1287
1301
|
specify "should construct proper SQL with dataset" do
|
|
1288
1302
|
@db.create_view :test, @db[:items].select(:a, :b).order(:c)
|
|
1289
1303
|
@db.sqls.should == ['CREATE VIEW test AS SELECT a, b FROM items ORDER BY c']
|
|
1290
|
-
@db.create_or_replace_view :sch__test, "SELECT * FROM xyz"
|
|
1291
|
-
@db.sqls.should == ['DROP VIEW sch.test', 'CREATE VIEW sch.test AS SELECT * FROM xyz']
|
|
1292
1304
|
end
|
|
1293
1305
|
|
|
1294
|
-
specify "should
|
|
1306
|
+
specify "should handle :columns option" do
|
|
1307
|
+
@db.create_view :test, @db[:items].select(:a, :b).order(:c), :columns=>[:d, :e]
|
|
1308
|
+
@db.sqls.should == ['CREATE VIEW test (d, e) AS SELECT a, b FROM items ORDER BY c']
|
|
1309
|
+
@db.create_view :test, @db[:items].select(:a, :b).order(:c), :columns=>%w'd e'
|
|
1310
|
+
@db.sqls.should == ['CREATE VIEW test (d, e) AS SELECT a, b FROM items ORDER BY c']
|
|
1311
|
+
@db.create_view :test, @db[:items].select(:a, :b).order(:c), :columns=>[Sequel.identifier('d'), Sequel.lit('e')]
|
|
1312
|
+
@db.sqls.should == ['CREATE VIEW test (d, e) AS SELECT a, b FROM items ORDER BY c']
|
|
1313
|
+
end
|
|
1314
|
+
|
|
1315
|
+
specify "should handle create_or_replace_view" do
|
|
1316
|
+
@db.create_or_replace_view :sch__test, "SELECT * FROM xyz"
|
|
1317
|
+
@db.sqls.should == ['DROP VIEW sch.test', 'CREATE VIEW sch.test AS SELECT * FROM xyz']
|
|
1295
1318
|
@db.create_or_replace_view :test, @db[:items].select(:a, :b).order(:c)
|
|
1296
1319
|
@db.sqls.should == ['DROP VIEW test', 'CREATE VIEW test AS SELECT a, b FROM items ORDER BY c']
|
|
1297
1320
|
@db.create_or_replace_view Sequel.identifier(:test), @db[:items].select(:a, :b).order(:c)
|
data/spec/core/spec_helper.rb
CHANGED
|
@@ -7,7 +7,6 @@ end
|
|
|
7
7
|
|
|
8
8
|
unless Object.const_defined?('Sequel')
|
|
9
9
|
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
|
10
|
-
SEQUEL_NO_CORE_EXTENSIONS = true
|
|
11
10
|
require 'sequel/core'
|
|
12
11
|
end
|
|
13
12
|
Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
|
|
@@ -38,7 +37,9 @@ end
|
|
|
38
37
|
|
|
39
38
|
if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
|
40
39
|
Sequel.extension :columns_introspection
|
|
41
|
-
Sequel::
|
|
40
|
+
Sequel::Database.extension :columns_introspection
|
|
41
|
+
Sequel.require 'adapters/mock'
|
|
42
|
+
Sequel::Mock::Dataset.send(:include, Sequel::ColumnsIntrospection)
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
Sequel.quote_identifiers = false
|
|
@@ -7,12 +7,8 @@ end
|
|
|
7
7
|
|
|
8
8
|
unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
|
|
9
9
|
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
else
|
|
13
|
-
require 'sequel/no_core_ext'
|
|
14
|
-
end
|
|
15
|
-
Sequel::Deprecation.backtrace_filter = false
|
|
10
|
+
require 'sequel'
|
|
11
|
+
Sequel::Deprecation.backtrace_filter = true
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
Sequel.quote_identifiers = false
|
|
@@ -21,10 +17,8 @@ Sequel.identifier_output_method = nil
|
|
|
21
17
|
|
|
22
18
|
Regexp.send(:include, Sequel::SQL::StringMethods)
|
|
23
19
|
String.send(:include, Sequel::SQL::StringMethods)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
if RUBY_VERSION < '1.9.0' && (dep_core_extensions.nil? || dep_core_extensions =~ /SYMBOL18/)
|
|
20
|
+
Sequel.extension :core_extensions
|
|
21
|
+
if RUBY_VERSION < '1.9.0'
|
|
28
22
|
Sequel.extension :ruby18_symbol_extensions
|
|
29
23
|
end
|
|
30
24
|
|
|
@@ -264,7 +258,7 @@ end
|
|
|
264
258
|
|
|
265
259
|
describe "Array#case and Hash#case" do
|
|
266
260
|
before do
|
|
267
|
-
@d = Sequel
|
|
261
|
+
@d = Sequel.mock.dataset
|
|
268
262
|
end
|
|
269
263
|
|
|
270
264
|
specify "should return SQL CASE expression" do
|
|
@@ -296,7 +290,7 @@ end
|
|
|
296
290
|
|
|
297
291
|
describe "Array#sql_value_list and #sql_array" do
|
|
298
292
|
before do
|
|
299
|
-
@d = Sequel
|
|
293
|
+
@d = Sequel.mock.dataset
|
|
300
294
|
end
|
|
301
295
|
|
|
302
296
|
specify "should treat the array as an SQL value list instead of conditions when used as a placeholder value" do
|
|
@@ -391,7 +385,7 @@ end
|
|
|
391
385
|
|
|
392
386
|
describe "#desc" do
|
|
393
387
|
before do
|
|
394
|
-
@ds = Sequel
|
|
388
|
+
@ds = Sequel.mock.dataset
|
|
395
389
|
end
|
|
396
390
|
|
|
397
391
|
specify "should format a DESC clause for a column ref" do
|
|
@@ -407,7 +401,7 @@ end
|
|
|
407
401
|
|
|
408
402
|
describe "#asc" do
|
|
409
403
|
before do
|
|
410
|
-
@ds = Sequel
|
|
404
|
+
@ds = Sequel.mock.dataset
|
|
411
405
|
end
|
|
412
406
|
|
|
413
407
|
specify "should format a ASC clause for a column ref" do
|
|
@@ -423,7 +417,7 @@ end
|
|
|
423
417
|
|
|
424
418
|
describe "#as" do
|
|
425
419
|
before do
|
|
426
|
-
@ds = Sequel
|
|
420
|
+
@ds = Sequel.mock.dataset
|
|
427
421
|
end
|
|
428
422
|
|
|
429
423
|
specify "should format a AS clause for a column ref" do
|
|
@@ -488,7 +482,7 @@ end
|
|
|
488
482
|
if RUBY_VERSION < '1.9.0'
|
|
489
483
|
describe "Symbol#[]" do
|
|
490
484
|
specify "should format an SQL Function" do
|
|
491
|
-
ds = Sequel
|
|
485
|
+
ds = Sequel.mock.dataset
|
|
492
486
|
ds.literal(:xyz[]).should == 'xyz()'
|
|
493
487
|
ds.literal(:xyz[1]).should == 'xyz(1)'
|
|
494
488
|
ds.literal(:xyz[1, 2, :abc[3]]).should == 'xyz(1, 2, abc(3))'
|
|
@@ -498,7 +492,7 @@ end
|
|
|
498
492
|
|
|
499
493
|
describe "Symbol#*" do
|
|
500
494
|
before do
|
|
501
|
-
@ds = Sequel
|
|
495
|
+
@ds = Sequel.mock.dataset
|
|
502
496
|
end
|
|
503
497
|
|
|
504
498
|
specify "should format a qualified wildcard if no argument" do
|
|
@@ -518,7 +512,7 @@ end
|
|
|
518
512
|
|
|
519
513
|
describe "Symbol" do
|
|
520
514
|
before do
|
|
521
|
-
@ds = Sequel
|
|
515
|
+
@ds = Sequel.mock.dataset
|
|
522
516
|
@ds.quote_identifiers = true
|
|
523
517
|
@ds.identifier_input_method = :upcase
|
|
524
518
|
end
|
|
@@ -634,7 +628,7 @@ end
|
|
|
634
628
|
describe "Postgres extensions integration" do
|
|
635
629
|
before do
|
|
636
630
|
@db = Sequel.mock
|
|
637
|
-
Sequel.extension(:pg_array, :pg_array_ops, :pg_hstore, :pg_hstore_ops, :pg_json, :pg_range, :pg_range_ops, :pg_row, :pg_row_ops)
|
|
631
|
+
Sequel.extension(:pg_array, :pg_array_ops, :pg_hstore, :pg_hstore_ops, :pg_json, :pg_json_ops, :pg_range, :pg_range_ops, :pg_row, :pg_row_ops)
|
|
638
632
|
end
|
|
639
633
|
|
|
640
634
|
it "Symbol#pg_array should return an ArrayOp" do
|
|
@@ -649,6 +643,10 @@ describe "Postgres extensions integration" do
|
|
|
649
643
|
@db.literal(:a.hstore['a']).should == "(a -> 'a')"
|
|
650
644
|
end
|
|
651
645
|
|
|
646
|
+
it "Symbol#pg_json should return an JSONOp" do
|
|
647
|
+
@db.literal(:a.pg_json[%w'a b']).should == "(a #> ARRAY['a','b'])"
|
|
648
|
+
end
|
|
649
|
+
|
|
652
650
|
it "Symbol#pg_range should return a RangeOp" do
|
|
653
651
|
@db.literal(:a.pg_range.lower).should == "lower(a)"
|
|
654
652
|
end
|
|
@@ -65,7 +65,7 @@ describe "arbtirary servers" do
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
specify "should work correctly with server_block plugin" do
|
|
68
|
-
@db.
|
|
68
|
+
@db.extension :server_block
|
|
69
69
|
@db.with_server(:host=>'host1', :database=>'db1') do
|
|
70
70
|
@db.synchronize do |c|
|
|
71
71
|
c.opts[:host].should == 'host1'
|
|
@@ -77,9 +77,8 @@ describe "arbtirary servers" do
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
|
|
81
80
|
specify "should respect multithreaded access with server block plugin" do
|
|
82
|
-
@db.
|
|
81
|
+
@db.extension :server_block
|
|
83
82
|
q, q1 = Queue.new, Queue.new
|
|
84
83
|
|
|
85
84
|
t = nil
|
|
@@ -15,61 +15,61 @@ describe "AssociationDependencies plugin" do
|
|
|
15
15
|
@Artist.one_to_one :first_album, :class=>@Album, :key=>:artist_id, :conditions=>{:position=>1}
|
|
16
16
|
@Artist.many_to_many :other_artists, :class=>@Artist, :join_table=>:aoa, :left_key=>:l, :right_key=>:r
|
|
17
17
|
@Album.many_to_one :artist, :class=>@Artist
|
|
18
|
-
|
|
18
|
+
DB.reset
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
specify "should allow destroying associated many_to_one associated object" do
|
|
22
22
|
@Album.add_association_dependencies :artist=>:destroy
|
|
23
23
|
@Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
|
|
24
|
-
|
|
24
|
+
DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
specify "should allow deleting associated many_to_one associated object" do
|
|
28
28
|
@Album.add_association_dependencies :artist=>:delete
|
|
29
29
|
@Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
|
|
30
|
-
|
|
30
|
+
DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE (artists.id = 2)']
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
specify "should allow destroying associated one_to_one associated object" do
|
|
34
34
|
@Artist.add_association_dependencies :first_album=>:destroy
|
|
35
35
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
36
|
-
|
|
36
|
+
DB.sqls.should == ['SELECT * FROM albums WHERE ((position = 1) AND (albums.artist_id = 2)) LIMIT 1', 'DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE id = 2']
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
specify "should allow deleting associated one_to_one associated object" do
|
|
40
40
|
@Artist.add_association_dependencies :first_album=>:delete
|
|
41
41
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
42
|
-
|
|
42
|
+
DB.sqls.should == ['DELETE FROM albums WHERE ((position = 1) AND (albums.artist_id = 2))', 'DELETE FROM artists WHERE id = 2']
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
specify "should allow destroying associated one_to_many objects" do
|
|
46
46
|
@Artist.add_association_dependencies :albums=>:destroy
|
|
47
47
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
48
|
-
|
|
48
|
+
DB.sqls.should == ['SELECT * FROM albums WHERE (albums.artist_id = 2)', 'DELETE FROM albums WHERE id = 1', 'DELETE FROM artists WHERE id = 2']
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
specify "should allow deleting associated one_to_many objects" do
|
|
52
52
|
@Artist.add_association_dependencies :albums=>:delete
|
|
53
53
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
54
|
-
|
|
54
|
+
DB.sqls.should == ['DELETE FROM albums WHERE (albums.artist_id = 2)', 'DELETE FROM artists WHERE id = 2']
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
specify "should allow nullifying associated one_to_one objects" do
|
|
58
58
|
@Artist.add_association_dependencies :first_album=>:nullify
|
|
59
59
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
60
|
-
|
|
60
|
+
DB.sqls.should == ['UPDATE albums SET artist_id = NULL WHERE ((position = 1) AND (artist_id = 2))', 'DELETE FROM artists WHERE id = 2']
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
specify "should allow nullifying associated one_to_many objects" do
|
|
64
64
|
@Artist.add_association_dependencies :albums=>:nullify
|
|
65
65
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
66
|
-
|
|
66
|
+
DB.sqls.should == ['UPDATE albums SET artist_id = NULL WHERE (artist_id = 2)', 'DELETE FROM artists WHERE id = 2']
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
specify "should allow nullifying associated many_to_many associations" do
|
|
70
70
|
@Artist.add_association_dependencies :other_artists=>:nullify
|
|
71
71
|
@Artist.load(:id=>2, :name=>'Ar').destroy
|
|
72
|
-
|
|
72
|
+
DB.sqls.should == ['DELETE FROM aoa WHERE (l = 2)', 'DELETE FROM artists WHERE id = 2']
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
specify "should raise an error if attempting to nullify a many_to_one association" do
|
|
@@ -97,21 +97,21 @@ describe "AssociationDependencies plugin" do
|
|
|
97
97
|
specify "should allow specifying association dependencies in the plugin call" do
|
|
98
98
|
@Album.plugin :association_dependencies, :artist=>:destroy
|
|
99
99
|
@Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
|
|
100
|
-
|
|
100
|
+
DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
specify "should work with subclasses" do
|
|
104
104
|
c = Class.new(@Album)
|
|
105
105
|
c.add_association_dependencies :artist=>:destroy
|
|
106
106
|
c.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
|
|
107
|
-
|
|
107
|
+
DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
|
|
108
108
|
|
|
109
109
|
@Album.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
|
|
110
|
-
|
|
110
|
+
DB.sqls.should == ['DELETE FROM albums WHERE id = 1']
|
|
111
111
|
|
|
112
112
|
@Album.add_association_dependencies :artist=>:destroy
|
|
113
113
|
c2 = Class.new(@Album)
|
|
114
114
|
c2.load(:id=>1, :name=>'Al', :artist_id=>2).destroy
|
|
115
|
-
|
|
115
|
+
DB.sqls.should == ['DELETE FROM albums WHERE id = 1', 'SELECT * FROM artists WHERE (artists.id = 2) LIMIT 1', 'DELETE FROM artists WHERE id = 2']
|
|
116
116
|
end
|
|
117
117
|
end
|