activerecord 2.0.5 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- data/CHANGELOG +168 -6
- data/README +27 -22
- data/RUNNING_UNIT_TESTS +7 -4
- data/Rakefile +22 -25
- data/lib/active_record.rb +8 -2
- data/lib/active_record/aggregations.rb +21 -12
- data/lib/active_record/association_preload.rb +277 -0
- data/lib/active_record/associations.rb +481 -295
- data/lib/active_record/associations/association_collection.rb +162 -37
- data/lib/active_record/associations/association_proxy.rb +71 -7
- data/lib/active_record/associations/belongs_to_association.rb +5 -3
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +5 -6
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +12 -64
- data/lib/active_record/associations/has_many_association.rb +8 -73
- data/lib/active_record/associations/has_many_through_association.rb +68 -117
- data/lib/active_record/associations/has_one_association.rb +7 -5
- data/lib/active_record/associations/has_one_through_association.rb +28 -0
- data/lib/active_record/attribute_methods.rb +69 -19
- data/lib/active_record/base.rb +496 -275
- data/lib/active_record/calculations.rb +28 -21
- data/lib/active_record/callbacks.rb +9 -38
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +3 -2
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +6 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +232 -45
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +141 -27
- data/lib/active_record/connection_adapters/abstract_adapter.rb +9 -13
- data/lib/active_record/connection_adapters/mysql_adapter.rb +57 -24
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +143 -42
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +18 -10
- data/lib/active_record/dirty.rb +158 -0
- data/lib/active_record/fixtures.rb +121 -156
- data/lib/active_record/locking/optimistic.rb +14 -11
- data/lib/active_record/locking/pessimistic.rb +2 -2
- data/lib/active_record/migration.rb +157 -77
- data/lib/active_record/named_scope.rb +163 -0
- data/lib/active_record/observer.rb +19 -5
- data/lib/active_record/reflection.rb +34 -14
- data/lib/active_record/schema.rb +7 -14
- data/lib/active_record/schema_dumper.rb +4 -4
- data/lib/active_record/serialization.rb +5 -5
- data/lib/active_record/serializers/json_serializer.rb +37 -28
- data/lib/active_record/serializers/xml_serializer.rb +52 -29
- data/lib/active_record/test_case.rb +36 -0
- data/lib/active_record/timestamp.rb +4 -4
- data/lib/active_record/transactions.rb +3 -3
- data/lib/active_record/validations.rb +182 -248
- data/lib/active_record/version.rb +2 -2
- data/test/{fixtures → assets}/example.log +0 -0
- data/test/{fixtures → assets}/flowers.jpg +0 -0
- data/test/cases/aaa_create_tables_test.rb +24 -0
- data/test/cases/active_schema_test_mysql.rb +95 -0
- data/test/cases/active_schema_test_postgresql.rb +24 -0
- data/test/{adapter_test.rb → cases/adapter_test.rb} +15 -14
- data/test/{adapter_test_sqlserver.rb → cases/adapter_test_sqlserver.rb} +95 -95
- data/test/{aggregations_test.rb → cases/aggregations_test.rb} +20 -20
- data/test/{ar_schema_test.rb → cases/ar_schema_test.rb} +6 -6
- data/test/cases/associations/belongs_to_associations_test.rb +412 -0
- data/test/{associations → cases/associations}/callbacks_test.rb +24 -10
- data/test/{associations → cases/associations}/cascaded_eager_loading_test.rb +18 -17
- data/test/cases/associations/eager_load_nested_include_test.rb +83 -0
- data/test/{associations → cases/associations}/eager_singularization_test.rb +5 -5
- data/test/{associations → cases/associations}/eager_test.rb +216 -51
- data/test/{associations → cases/associations}/extension_test.rb +8 -8
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +684 -0
- data/test/cases/associations/has_many_associations_test.rb +932 -0
- data/test/cases/associations/has_many_through_associations_test.rb +190 -0
- data/test/cases/associations/has_one_associations_test.rb +323 -0
- data/test/cases/associations/has_one_through_associations_test.rb +74 -0
- data/test/{associations → cases/associations}/inner_join_association_test.rb +20 -20
- data/test/{associations → cases/associations}/join_model_test.rb +175 -35
- data/test/cases/associations_test.rb +262 -0
- data/test/{attribute_methods_test.rb → cases/attribute_methods_test.rb} +103 -11
- data/test/{base_test.rb → cases/base_test.rb} +338 -191
- data/test/{binary_test.rb → cases/binary_test.rb} +6 -4
- data/test/{calculations_test.rb → cases/calculations_test.rb} +35 -23
- data/test/{callbacks_test.rb → cases/callbacks_test.rb} +7 -7
- data/test/{class_inheritable_attributes_test.rb → cases/class_inheritable_attributes_test.rb} +3 -3
- data/test/{column_alias_test.rb → cases/column_alias_test.rb} +3 -3
- data/test/{connection_test_firebird.rb → cases/connection_test_firebird.rb} +2 -2
- data/test/{connection_test_mysql.rb → cases/connection_test_mysql.rb} +2 -2
- data/test/{copy_table_test_sqlite.rb → cases/copy_table_test_sqlite.rb} +13 -13
- data/test/{datatype_test_postgresql.rb → cases/datatype_test_postgresql.rb} +8 -8
- data/test/{date_time_test.rb → cases/date_time_test.rb} +5 -5
- data/test/{default_test_firebird.rb → cases/default_test_firebird.rb} +3 -3
- data/test/{defaults_test.rb → cases/defaults_test.rb} +8 -6
- data/test/{deprecated_finder_test.rb → cases/deprecated_finder_test.rb} +3 -3
- data/test/cases/dirty_test.rb +163 -0
- data/test/cases/finder_respond_to_test.rb +76 -0
- data/test/{finder_test.rb → cases/finder_test.rb} +266 -33
- data/test/{fixtures_test.rb → cases/fixtures_test.rb} +88 -72
- data/test/cases/helper.rb +47 -0
- data/test/{inheritance_test.rb → cases/inheritance_test.rb} +61 -17
- data/test/cases/invalid_date_test.rb +24 -0
- data/test/{json_serialization_test.rb → cases/json_serialization_test.rb} +36 -11
- data/test/{lifecycle_test.rb → cases/lifecycle_test.rb} +16 -13
- data/test/{locking_test.rb → cases/locking_test.rb} +17 -10
- data/test/{method_scoping_test.rb → cases/method_scoping_test.rb} +75 -39
- data/test/{migration_test.rb → cases/migration_test.rb} +420 -80
- data/test/{migration_test_firebird.rb → cases/migration_test_firebird.rb} +3 -3
- data/test/{mixin_test.rb → cases/mixin_test.rb} +7 -6
- data/test/{modules_test.rb → cases/modules_test.rb} +11 -6
- data/test/{multiple_db_test.rb → cases/multiple_db_test.rb} +5 -5
- data/test/cases/named_scope_test.rb +157 -0
- data/test/{pk_test.rb → cases/pk_test.rb} +10 -10
- data/test/{query_cache_test.rb → cases/query_cache_test.rb} +12 -10
- data/test/{readonly_test.rb → cases/readonly_test.rb} +11 -11
- data/test/{reflection_test.rb → cases/reflection_test.rb} +15 -14
- data/test/{reserved_word_test_mysql.rb → cases/reserved_word_test_mysql.rb} +4 -5
- data/test/{schema_authorization_test_postgresql.rb → cases/schema_authorization_test_postgresql.rb} +5 -5
- data/test/cases/schema_dumper_test.rb +138 -0
- data/test/cases/schema_test_postgresql.rb +102 -0
- data/test/{serialization_test.rb → cases/serialization_test.rb} +7 -7
- data/test/{synonym_test_oracle.rb → cases/synonym_test_oracle.rb} +5 -5
- data/test/{table_name_test_sqlserver.rb → cases/table_name_test_sqlserver.rb} +3 -3
- data/test/{threaded_connections_test.rb → cases/threaded_connections_test.rb} +7 -7
- data/test/{transactions_test.rb → cases/transactions_test.rb} +31 -5
- data/test/{unconnected_test.rb → cases/unconnected_test.rb} +2 -2
- data/test/{validations_test.rb → cases/validations_test.rb} +141 -39
- data/test/{xml_serialization_test.rb → cases/xml_serialization_test.rb} +12 -12
- data/test/config.rb +5 -0
- data/test/connections/native_db2/connection.rb +1 -1
- data/test/connections/native_firebird/connection.rb +1 -1
- data/test/connections/native_frontbase/connection.rb +1 -1
- data/test/connections/native_mysql/connection.rb +1 -1
- data/test/connections/native_openbase/connection.rb +1 -1
- data/test/connections/native_oracle/connection.rb +1 -1
- data/test/connections/native_postgresql/connection.rb +1 -3
- data/test/connections/native_sqlite/connection.rb +2 -2
- data/test/connections/native_sqlite3/connection.rb +2 -2
- data/test/connections/native_sqlite3/in_memory_connection.rb +3 -3
- data/test/connections/native_sybase/connection.rb +1 -1
- data/test/fixtures/author_addresses.yml +5 -0
- data/test/fixtures/authors.yml +2 -0
- data/test/fixtures/clubs.yml +6 -0
- data/test/fixtures/jobs.yml +7 -0
- data/test/fixtures/members.yml +4 -0
- data/test/fixtures/memberships.yml +20 -0
- data/test/fixtures/owners.yml +7 -0
- data/test/fixtures/people.yml +4 -1
- data/test/fixtures/pets.yml +14 -0
- data/test/fixtures/posts.yml +1 -0
- data/test/fixtures/price_estimates.yml +7 -0
- data/test/fixtures/readers.yml +5 -0
- data/test/fixtures/references.yml +17 -0
- data/test/fixtures/sponsors.yml +9 -0
- data/test/fixtures/subscribers.yml +7 -0
- data/test/fixtures/subscriptions.yml +12 -0
- data/test/fixtures/taggings.yml +4 -1
- data/test/fixtures/topics.yml +22 -2
- data/test/fixtures/warehouse-things.yml +3 -0
- data/test/{fixtures/migrations_with_decimal → migrations/decimal}/1_give_me_big_numbers.rb +0 -0
- data/test/{fixtures/migrations_with_duplicate → migrations/duplicate}/1_people_have_last_names.rb +1 -1
- data/test/{fixtures/migrations_with_duplicate → migrations/duplicate}/2_we_need_reminders.rb +1 -1
- data/test/{fixtures/migrations_with_duplicate → migrations/duplicate}/3_foo.rb +0 -0
- data/test/{fixtures/migrations → migrations/duplicate}/3_innocent_jointable.rb +0 -0
- data/test/migrations/duplicate_names/20080507052938_chunky.rb +7 -0
- data/test/migrations/duplicate_names/20080507053028_chunky.rb +7 -0
- data/test/{fixtures/migrations_with_duplicate → migrations/interleaved/pass_1}/3_innocent_jointable.rb +0 -0
- data/test/{fixtures/migrations → migrations/interleaved/pass_2}/1_people_have_last_names.rb +1 -1
- data/test/{fixtures/migrations_with_missing_versions/4_innocent_jointable.rb → migrations/interleaved/pass_2/3_innocent_jointable.rb} +0 -0
- data/test/{fixtures/migrations_with_missing_versions → migrations/interleaved/pass_3}/1_people_have_last_names.rb +1 -1
- data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +8 -0
- data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +12 -0
- data/test/{fixtures/migrations_with_missing_versions → migrations/missing}/1000_people_have_middle_names.rb +1 -1
- data/test/migrations/missing/1_people_have_last_names.rb +9 -0
- data/test/{fixtures/migrations_with_missing_versions → migrations/missing}/3_we_need_reminders.rb +1 -1
- data/test/migrations/missing/4_innocent_jointable.rb +12 -0
- data/test/migrations/valid/1_people_have_last_names.rb +9 -0
- data/test/{fixtures/migrations → migrations/valid}/2_we_need_reminders.rb +1 -1
- data/test/migrations/valid/3_innocent_jointable.rb +12 -0
- data/test/{fixtures → models}/author.rb +28 -4
- data/test/{fixtures → models}/auto_id.rb +0 -0
- data/test/{fixtures → models}/binary.rb +0 -0
- data/test/{fixtures → models}/book.rb +0 -0
- data/test/{fixtures → models}/categorization.rb +0 -0
- data/test/{fixtures → models}/category.rb +8 -5
- data/test/{fixtures → models}/citation.rb +0 -0
- data/test/models/club.rb +7 -0
- data/test/{fixtures → models}/column_name.rb +0 -0
- data/test/{fixtures → models}/comment.rb +5 -3
- data/test/{fixtures → models}/company.rb +15 -6
- data/test/{fixtures → models}/company_in_module.rb +5 -3
- data/test/{fixtures → models}/computer.rb +0 -1
- data/test/{fixtures → models}/contact.rb +1 -1
- data/test/{fixtures → models}/course.rb +0 -0
- data/test/{fixtures → models}/customer.rb +8 -8
- data/test/{fixtures → models}/default.rb +0 -0
- data/test/{fixtures → models}/developer.rb +14 -10
- data/test/{fixtures → models}/edge.rb +0 -0
- data/test/{fixtures → models}/entrant.rb +0 -0
- data/test/models/guid.rb +2 -0
- data/test/{fixtures → models}/item.rb +0 -0
- data/test/models/job.rb +5 -0
- data/test/{fixtures → models}/joke.rb +0 -0
- data/test/{fixtures → models}/keyboard.rb +0 -0
- data/test/{fixtures → models}/legacy_thing.rb +0 -0
- data/test/{fixtures → models}/matey.rb +0 -0
- data/test/models/member.rb +9 -0
- data/test/models/membership.rb +9 -0
- data/test/{fixtures → models}/minimalistic.rb +0 -0
- data/test/{fixtures → models}/mixed_case_monkey.rb +0 -0
- data/test/{fixtures → models}/movie.rb +0 -0
- data/test/{fixtures → models}/order.rb +2 -2
- data/test/models/owner.rb +4 -0
- data/test/{fixtures → models}/parrot.rb +0 -0
- data/test/models/person.rb +10 -0
- data/test/models/pet.rb +4 -0
- data/test/models/pirate.rb +9 -0
- data/test/{fixtures → models}/post.rb +23 -2
- data/test/models/price_estimate.rb +3 -0
- data/test/{fixtures → models}/project.rb +1 -0
- data/test/{fixtures → models}/reader.rb +0 -0
- data/test/models/reference.rb +4 -0
- data/test/{fixtures → models}/reply.rb +7 -5
- data/test/{fixtures → models}/ship.rb +0 -0
- data/test/models/sponsor.rb +4 -0
- data/test/{fixtures → models}/subject.rb +0 -0
- data/test/{fixtures → models}/subscriber.rb +2 -0
- data/test/models/subscription.rb +4 -0
- data/test/{fixtures → models}/tag.rb +0 -0
- data/test/{fixtures → models}/tagging.rb +0 -0
- data/test/{fixtures → models}/task.rb +0 -0
- data/test/{fixtures → models}/topic.rb +32 -4
- data/test/{fixtures → models}/treasure.rb +2 -0
- data/test/{fixtures → models}/vertex.rb +0 -0
- data/test/models/warehouse_thing.rb +5 -0
- data/test/schema/mysql_specific_schema.rb +12 -0
- data/test/schema/postgresql_specific_schema.rb +103 -0
- data/test/schema/schema.rb +421 -0
- data/test/schema/schema2.rb +6 -0
- data/test/schema/sqlite_specific_schema.rb +25 -0
- data/test/schema/sqlserver_specific_schema.rb +5 -0
- metadata +192 -176
- data/test/aaa_create_tables_test.rb +0 -72
- data/test/abstract_unit.rb +0 -84
- data/test/active_schema_test_mysql.rb +0 -46
- data/test/all.sh +0 -8
- data/test/association_inheritance_reload.rb +0 -14
- data/test/associations_test.rb +0 -2177
- data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +0 -1
- data/test/fixtures/bad_fixtures/attr_with_spaces +0 -1
- data/test/fixtures/bad_fixtures/blank_line +0 -3
- data/test/fixtures/bad_fixtures/duplicate_attributes +0 -3
- data/test/fixtures/bad_fixtures/missing_value +0 -1
- data/test/fixtures/db_definitions/db2.drop.sql +0 -33
- data/test/fixtures/db_definitions/db2.sql +0 -235
- data/test/fixtures/db_definitions/db22.drop.sql +0 -2
- data/test/fixtures/db_definitions/db22.sql +0 -5
- data/test/fixtures/db_definitions/firebird.drop.sql +0 -65
- data/test/fixtures/db_definitions/firebird.sql +0 -310
- data/test/fixtures/db_definitions/firebird2.drop.sql +0 -2
- data/test/fixtures/db_definitions/firebird2.sql +0 -6
- data/test/fixtures/db_definitions/frontbase.drop.sql +0 -33
- data/test/fixtures/db_definitions/frontbase.sql +0 -273
- data/test/fixtures/db_definitions/frontbase2.drop.sql +0 -1
- data/test/fixtures/db_definitions/frontbase2.sql +0 -4
- data/test/fixtures/db_definitions/openbase.drop.sql +0 -2
- data/test/fixtures/db_definitions/openbase.sql +0 -318
- data/test/fixtures/db_definitions/openbase2.drop.sql +0 -2
- data/test/fixtures/db_definitions/openbase2.sql +0 -7
- data/test/fixtures/db_definitions/oracle.drop.sql +0 -67
- data/test/fixtures/db_definitions/oracle.sql +0 -330
- data/test/fixtures/db_definitions/oracle2.drop.sql +0 -2
- data/test/fixtures/db_definitions/oracle2.sql +0 -6
- data/test/fixtures/db_definitions/postgresql.drop.sql +0 -44
- data/test/fixtures/db_definitions/postgresql.sql +0 -292
- data/test/fixtures/db_definitions/postgresql2.drop.sql +0 -2
- data/test/fixtures/db_definitions/postgresql2.sql +0 -4
- data/test/fixtures/db_definitions/schema.rb +0 -354
- data/test/fixtures/db_definitions/schema2.rb +0 -11
- data/test/fixtures/db_definitions/sqlite.drop.sql +0 -33
- data/test/fixtures/db_definitions/sqlite.sql +0 -219
- data/test/fixtures/db_definitions/sqlite2.drop.sql +0 -2
- data/test/fixtures/db_definitions/sqlite2.sql +0 -5
- data/test/fixtures/db_definitions/sybase.drop.sql +0 -35
- data/test/fixtures/db_definitions/sybase.sql +0 -222
- data/test/fixtures/db_definitions/sybase2.drop.sql +0 -4
- data/test/fixtures/db_definitions/sybase2.sql +0 -5
- data/test/fixtures/developers_projects/david_action_controller +0 -3
- data/test/fixtures/developers_projects/david_active_record +0 -3
- data/test/fixtures/developers_projects/jamis_active_record +0 -2
- data/test/fixtures/person.rb +0 -4
- data/test/fixtures/pirate.rb +0 -5
- data/test/fixtures/subscribers/first +0 -2
- data/test/fixtures/subscribers/second +0 -2
- data/test/schema_dumper_test.rb +0 -131
- data/test/schema_test_postgresql.rb +0 -64
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'models/topic'
|
3
|
+
|
4
|
+
class InvalidDateTest < Test::Unit::TestCase
|
5
|
+
def test_assign_valid_dates
|
6
|
+
valid_dates = [[2007, 11, 30], [1993, 2, 28], [2008, 2, 29]]
|
7
|
+
|
8
|
+
invalid_dates = [[2007, 11, 31], [1993, 2, 29], [2007, 2, 29]]
|
9
|
+
|
10
|
+
topic = Topic.new
|
11
|
+
|
12
|
+
valid_dates.each do |date_src|
|
13
|
+
topic = Topic.new("last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s)
|
14
|
+
assert_equal(topic.last_read, Date.new(*date_src))
|
15
|
+
end
|
16
|
+
|
17
|
+
invalid_dates.each do |date_src|
|
18
|
+
assert_nothing_raised do
|
19
|
+
topic = Topic.new({"last_read(1i)" => date_src[0].to_s, "last_read(2i)" => date_src[1].to_s, "last_read(3i)" => date_src[2].to_s})
|
20
|
+
assert_equal(topic.last_read, Time.local(*date_src).to_date, "The date should be modified according to the behaviour of the Time object")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,12 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
|
9
|
-
class JsonSerializationTest <
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/contact'
|
3
|
+
require 'models/post'
|
4
|
+
require 'models/author'
|
5
|
+
require 'models/tagging'
|
6
|
+
require 'models/tag'
|
7
|
+
require 'models/comment'
|
8
|
+
|
9
|
+
class JsonSerializationTest < ActiveRecord::TestCase
|
10
|
+
class NamespacedContact < Contact
|
11
|
+
column :name, :string
|
12
|
+
end
|
13
|
+
|
10
14
|
def setup
|
11
15
|
@contact = Contact.new(
|
12
16
|
:name => 'Konata Izumi',
|
@@ -18,6 +22,27 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
18
22
|
)
|
19
23
|
end
|
20
24
|
|
25
|
+
def test_should_demodulize_root_in_json
|
26
|
+
NamespacedContact.include_root_in_json = true
|
27
|
+
@contact = NamespacedContact.new :name => 'whatever'
|
28
|
+
json = @contact.to_json
|
29
|
+
assert_match %r{^\{"namespaced_contact": \{}, json
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_include_root_in_json
|
33
|
+
Contact.include_root_in_json = true
|
34
|
+
json = @contact.to_json
|
35
|
+
|
36
|
+
assert_match %r{^\{"contact": \{}, json
|
37
|
+
assert_match %r{"name": "Konata Izumi"}, json
|
38
|
+
assert_match %r{"age": 16}, json
|
39
|
+
assert json.include?(%("created_at": #{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
|
40
|
+
assert_match %r{"awesome": true}, json
|
41
|
+
assert_match %r{"preferences": \{"shows": "anime"\}}, json
|
42
|
+
ensure
|
43
|
+
Contact.include_root_in_json = false
|
44
|
+
end
|
45
|
+
|
21
46
|
def test_should_encode_all_encodable_attributes
|
22
47
|
json = @contact.to_json
|
23
48
|
|
@@ -63,7 +88,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
63
88
|
end
|
64
89
|
end
|
65
90
|
|
66
|
-
class DatabaseConnectedJsonEncodingTest <
|
91
|
+
class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
|
67
92
|
fixtures :authors, :posts, :comments, :tags, :taggings
|
68
93
|
|
69
94
|
def setup
|
@@ -151,7 +176,7 @@ class DatabaseConnectedJsonEncodingTest < Test::Unit::TestCase
|
|
151
176
|
def test_should_allow_except_option_for_list_of_authors
|
152
177
|
authors = [@david, @mary]
|
153
178
|
|
154
|
-
assert_equal %([{"id": 1}, {"id": 2}]), authors.to_json(:except => [:name, :author_address_id])
|
179
|
+
assert_equal %([{"id": 1}, {"id": 2}]), authors.to_json(:except => [:name, :author_address_id, :author_address_extra_id])
|
155
180
|
end
|
156
181
|
|
157
182
|
def test_should_allow_includes_for_list_of_authors
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/topic'
|
3
|
+
require 'models/developer'
|
4
|
+
require 'models/reply'
|
5
5
|
|
6
6
|
class Topic; def after_find() end end
|
7
7
|
class Developer; def after_find() end end
|
@@ -26,11 +26,11 @@ class TopicManualObserver
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
class
|
29
|
+
class TopicaAuditor < ActiveRecord::Observer
|
30
30
|
observe :topic
|
31
|
-
|
31
|
+
|
32
32
|
attr_reader :topic
|
33
|
-
|
33
|
+
|
34
34
|
def after_find(topic)
|
35
35
|
@topic = topic
|
36
36
|
end
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
|
39
39
|
class TopicObserver < ActiveRecord::Observer
|
40
40
|
attr_reader :topic
|
41
|
-
|
41
|
+
|
42
42
|
def after_find(topic)
|
43
43
|
@topic = topic
|
44
44
|
end
|
@@ -64,13 +64,13 @@ class MultiObserver < ActiveRecord::Observer
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
class LifecycleTest <
|
67
|
+
class LifecycleTest < ActiveRecord::TestCase
|
68
68
|
fixtures :topics, :developers
|
69
69
|
|
70
70
|
def test_before_destroy
|
71
|
-
|
72
|
-
Topic.find(1).destroy
|
73
|
-
assert_equal
|
71
|
+
original_count = Topic.count
|
72
|
+
(topic_to_be_destroyed = Topic.find(1)).destroy
|
73
|
+
assert_equal original_count - (1 + topic_to_be_destroyed.replies.size), Topic.count
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_after_save
|
@@ -95,7 +95,9 @@ class LifecycleTest < Test::Unit::TestCase
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_auto_observer
|
98
|
-
topic_observer =
|
98
|
+
topic_observer = TopicaAuditor.instance
|
99
|
+
assert_nil TopicaAuditor.observed_class
|
100
|
+
assert_equal [Topic], TopicaAuditor.instance.observed_classes.to_a
|
99
101
|
|
100
102
|
topic = Topic.find(1)
|
101
103
|
assert_equal topic.title, topic_observer.topic.title
|
@@ -103,6 +105,7 @@ class LifecycleTest < Test::Unit::TestCase
|
|
103
105
|
|
104
106
|
def test_inferred_auto_observer
|
105
107
|
topic_observer = TopicObserver.instance
|
108
|
+
assert_equal Topic, TopicObserver.observed_class
|
106
109
|
|
107
110
|
topic = Topic.find(1)
|
108
111
|
assert_equal topic.title, topic_observer.topic.title
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/person'
|
3
|
+
require 'models/reader'
|
4
|
+
require 'models/legacy_thing'
|
5
|
+
require 'models/reference'
|
5
6
|
|
6
7
|
class LockWithoutDefault < ActiveRecord::Base; end
|
7
8
|
|
@@ -14,8 +15,8 @@ class ReadonlyFirstNamePerson < Person
|
|
14
15
|
attr_readonly :first_name
|
15
16
|
end
|
16
17
|
|
17
|
-
class OptimisticLockingTest <
|
18
|
-
fixtures :people, :legacy_things
|
18
|
+
class OptimisticLockingTest < ActiveRecord::TestCase
|
19
|
+
fixtures :people, :legacy_things, :references
|
19
20
|
|
20
21
|
# need to disable transactional fixtures, because otherwise the sqlite3
|
21
22
|
# adapter (at least) chokes when we try and change the schema in the middle
|
@@ -34,7 +35,7 @@ class OptimisticLockingTest < Test::Unit::TestCase
|
|
34
35
|
|
35
36
|
assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
def test_lock_repeating
|
39
40
|
p1 = Person.find(1)
|
40
41
|
p2 = Person.find(1)
|
@@ -64,7 +65,7 @@ class OptimisticLockingTest < Test::Unit::TestCase
|
|
64
65
|
|
65
66
|
assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
|
66
67
|
end
|
67
|
-
|
68
|
+
|
68
69
|
def test_lock_new_with_nil
|
69
70
|
p1 = Person.new(:first_name => 'anika')
|
70
71
|
p1.save!
|
@@ -72,7 +73,7 @@ class OptimisticLockingTest < Test::Unit::TestCase
|
|
72
73
|
p1.save!
|
73
74
|
assert_equal 1, p1.lock_version
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
|
77
78
|
def test_lock_column_name_existing
|
78
79
|
t1 = LegacyThing.find(1)
|
@@ -138,6 +139,12 @@ class OptimisticLockingTest < Test::Unit::TestCase
|
|
138
139
|
end
|
139
140
|
end
|
140
141
|
end
|
142
|
+
|
143
|
+
def test_quote_table_name
|
144
|
+
ref = references(:michael_magician)
|
145
|
+
ref.favourite = !ref.favourite
|
146
|
+
assert ref.save
|
147
|
+
end
|
141
148
|
|
142
149
|
private
|
143
150
|
|
@@ -176,7 +183,7 @@ end
|
|
176
183
|
# TODO: The SQL Server, Sybase, and OpenBase adapters currently have no support for pessimistic locking
|
177
184
|
|
178
185
|
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
|
179
|
-
class PessimisticLockingTest <
|
186
|
+
class PessimisticLockingTest < ActiveRecord::TestCase
|
180
187
|
self.use_transactional_fixtures = false
|
181
188
|
fixtures :people, :readers
|
182
189
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
|
8
|
-
class MethodScopingTest <
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/developer'
|
3
|
+
require 'models/project'
|
4
|
+
require 'models/comment'
|
5
|
+
require 'models/post'
|
6
|
+
require 'models/category'
|
7
|
+
|
8
|
+
class MethodScopingTest < ActiveRecord::TestCase
|
9
9
|
fixtures :developers, :projects, :comments, :posts
|
10
|
-
|
10
|
+
|
11
11
|
def test_set_conditions
|
12
12
|
Developer.with_scope(:find => { :conditions => 'just a test...' }) do
|
13
13
|
assert_equal 'just a test...', Developer.send(:current_scoped_methods)[:find][:conditions]
|
@@ -19,46 +19,62 @@ class MethodScopingTest < Test::Unit::TestCase
|
|
19
19
|
assert_nothing_raised { Developer.find(1) }
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_scoped_find_first
|
24
24
|
Developer.with_scope(:find => { :conditions => "salary = 100000" }) do
|
25
25
|
assert_equal Developer.find(10), Developer.find(:first, :order => 'name')
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def test_scoped_find_combines_conditions
|
30
30
|
Developer.with_scope(:find => { :conditions => "salary = 9000" }) do
|
31
31
|
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => "name = 'Jamis'")
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_scoped_find_sanitizes_conditions
|
36
36
|
Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
|
37
37
|
assert_equal developers(:poor_jamis), Developer.find(:first)
|
38
|
-
end
|
38
|
+
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_scoped_find_combines_and_sanitizes_conditions
|
42
42
|
Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
|
43
43
|
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => ['name = ?', 'Jamis'])
|
44
|
-
end
|
44
|
+
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_scoped_find_all
|
48
48
|
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
|
49
49
|
assert_equal [developers(:david)], Developer.find(:all)
|
50
|
-
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_scoped_find_select
|
54
|
+
Developer.with_scope(:find => { :select => "id, name" }) do
|
55
|
+
developer = Developer.find(:first, :conditions => "name = 'David'")
|
56
|
+
assert_equal "David", developer.name
|
57
|
+
assert !developer.has_attribute?(:salary)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_options_select_replaces_scope_select
|
62
|
+
Developer.with_scope(:find => { :select => "id, name" }) do
|
63
|
+
developer = Developer.find(:first, :select => 'id, salary', :conditions => "name = 'David'")
|
64
|
+
assert_equal 80000, developer.salary
|
65
|
+
assert !developer.has_attribute?(:name)
|
66
|
+
end
|
51
67
|
end
|
52
|
-
|
68
|
+
|
53
69
|
def test_scoped_count
|
54
70
|
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
|
55
71
|
assert_equal 1, Developer.count
|
56
|
-
end
|
72
|
+
end
|
57
73
|
|
58
74
|
Developer.with_scope(:find => { :conditions => 'salary = 100000' }) do
|
59
75
|
assert_equal 8, Developer.count
|
60
76
|
assert_equal 1, Developer.count(:conditions => "name LIKE 'fixture_1%'")
|
61
|
-
end
|
77
|
+
end
|
62
78
|
end
|
63
79
|
|
64
80
|
def test_scoped_find_include
|
@@ -70,7 +86,7 @@ class MethodScopingTest < Test::Unit::TestCase
|
|
70
86
|
assert !scoped_developers.include?(developers(:jamis))
|
71
87
|
assert_equal 1, scoped_developers.size
|
72
88
|
end
|
73
|
-
|
89
|
+
|
74
90
|
def test_scoped_count_include
|
75
91
|
# with the include, will retrieve only developers for the given project
|
76
92
|
Developer.with_scope(:find => { :include => :projects }) do
|
@@ -125,7 +141,7 @@ class MethodScopingTest < Test::Unit::TestCase
|
|
125
141
|
end
|
126
142
|
end
|
127
143
|
|
128
|
-
class NestedScopingTest <
|
144
|
+
class NestedScopingTest < ActiveRecord::TestCase
|
129
145
|
fixtures :developers, :projects, :comments, :posts
|
130
146
|
|
131
147
|
def test_merge_options
|
@@ -150,7 +166,7 @@ class NestedScopingTest < Test::Unit::TestCase
|
|
150
166
|
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
|
151
167
|
Developer.with_scope(:find => { :conditions => 'salary = 80000' }) do
|
152
168
|
appended_condition = Developer.instance_eval('current_scoped_methods')[:find][:conditions]
|
153
|
-
assert_equal("(
|
169
|
+
assert_equal("(name = 'David') AND (salary = 80000)", appended_condition)
|
154
170
|
assert_equal(1, Developer.count)
|
155
171
|
end
|
156
172
|
Developer.with_scope(:find => { :conditions => "name = 'Maiha'" }) do
|
@@ -163,7 +179,7 @@ class NestedScopingTest < Test::Unit::TestCase
|
|
163
179
|
Developer.with_scope(:find => { :conditions => 'salary = 80000', :limit => 10 }) do
|
164
180
|
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
|
165
181
|
merged_option = Developer.instance_eval('current_scoped_methods')[:find]
|
166
|
-
assert_equal({ :conditions => "(
|
182
|
+
assert_equal({ :conditions => "(salary = 80000) AND (name = 'David')", :limit => 10 }, merged_option)
|
167
183
|
end
|
168
184
|
end
|
169
185
|
end
|
@@ -184,7 +200,7 @@ class NestedScopingTest < Test::Unit::TestCase
|
|
184
200
|
assert_nothing_raised { Developer.find(1) }
|
185
201
|
assert_equal('David', Developer.find(:first).name)
|
186
202
|
end
|
187
|
-
end
|
203
|
+
end
|
188
204
|
end
|
189
205
|
|
190
206
|
def test_nested_scoped_find_merged_include
|
@@ -194,31 +210,31 @@ class NestedScopingTest < Test::Unit::TestCase
|
|
194
210
|
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
195
211
|
assert_equal('David', Developer.find(:first).name)
|
196
212
|
end
|
197
|
-
end
|
198
|
-
|
213
|
+
end
|
214
|
+
|
199
215
|
# the nested scope doesn't remove the first :include
|
200
216
|
Developer.with_scope(:find => { :include => :projects, :conditions => "projects.id = 2" }) do
|
201
217
|
Developer.with_scope(:find => { :include => [] }) do
|
202
218
|
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
203
219
|
assert_equal('David', Developer.find(:first).name)
|
204
220
|
end
|
205
|
-
end
|
206
|
-
|
221
|
+
end
|
222
|
+
|
207
223
|
# mixing array and symbol include's will merge correctly
|
208
224
|
Developer.with_scope(:find => { :include => [:projects], :conditions => "projects.id = 2" }) do
|
209
225
|
Developer.with_scope(:find => { :include => :projects }) do
|
210
226
|
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
211
227
|
assert_equal('David', Developer.find(:first).name)
|
212
228
|
end
|
213
|
-
end
|
229
|
+
end
|
214
230
|
end
|
215
|
-
|
231
|
+
|
216
232
|
def test_nested_scoped_find_replace_include
|
217
233
|
Developer.with_scope(:find => { :include => :projects }) do
|
218
234
|
Developer.with_exclusive_scope(:find => { :include => [] }) do
|
219
235
|
assert_equal 0, Developer.instance_eval('current_scoped_methods')[:find][:include].length
|
220
236
|
end
|
221
|
-
end
|
237
|
+
end
|
222
238
|
end
|
223
239
|
|
224
240
|
def test_three_level_nested_exclusive_scoped_find
|
@@ -275,6 +291,26 @@ class NestedScopingTest < Test::Unit::TestCase
|
|
275
291
|
end
|
276
292
|
end
|
277
293
|
|
294
|
+
def test_merged_scoped_find_on_blank_conditions
|
295
|
+
[nil, " ", [], {}].each do |blank|
|
296
|
+
Developer.with_scope(:find => {:conditions => blank}) do
|
297
|
+
Developer.with_scope(:find => {:conditions => blank}) do
|
298
|
+
assert_nothing_raised { Developer.find(:first) }
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_merged_scoped_find_on_blank_bind_conditions
|
305
|
+
[ [""], ["",{}] ].each do |blank|
|
306
|
+
Developer.with_scope(:find => {:conditions => blank}) do
|
307
|
+
Developer.with_scope(:find => {:conditions => blank}) do
|
308
|
+
assert_nothing_raised { Developer.find(:first) }
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
278
314
|
def test_immutable_nested_scope
|
279
315
|
options1 = { :conditions => "name = 'Jamis'" }
|
280
316
|
options2 = { :conditions => "name = 'David'" }
|
@@ -313,13 +349,13 @@ class NestedScopingTest < Test::Unit::TestCase
|
|
313
349
|
end
|
314
350
|
end
|
315
351
|
|
316
|
-
class HasManyScopingTest<
|
352
|
+
class HasManyScopingTest< ActiveRecord::TestCase
|
317
353
|
fixtures :comments, :posts
|
318
|
-
|
354
|
+
|
319
355
|
def setup
|
320
356
|
@welcome = Post.find(1)
|
321
357
|
end
|
322
|
-
|
358
|
+
|
323
359
|
def test_forwarding_of_static_methods
|
324
360
|
assert_equal 'a comment...', Comment.what_are_you
|
325
361
|
assert_equal 'a comment...', @welcome.comments.what_are_you
|
@@ -329,7 +365,7 @@ class HasManyScopingTest< Test::Unit::TestCase
|
|
329
365
|
assert_equal 4, Comment.search_by_type('Comment').size
|
330
366
|
assert_equal 2, @welcome.comments.search_by_type('Comment').size
|
331
367
|
end
|
332
|
-
|
368
|
+
|
333
369
|
def test_forwarding_to_dynamic_finders
|
334
370
|
assert_equal 4, Comment.find_all_by_type('Comment').size
|
335
371
|
assert_equal 2, @welcome.comments.find_all_by_type('Comment').size
|
@@ -343,7 +379,7 @@ class HasManyScopingTest< Test::Unit::TestCase
|
|
343
379
|
end
|
344
380
|
|
345
381
|
|
346
|
-
class HasAndBelongsToManyScopingTest<
|
382
|
+
class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase
|
347
383
|
fixtures :posts, :categories, :categories_posts
|
348
384
|
|
349
385
|
def setup
|
@@ -373,7 +409,7 @@ end
|
|
373
409
|
# We disabled the scoping for has_one and belongs_to as we can't think of a proper use case
|
374
410
|
|
375
411
|
|
376
|
-
class BelongsToScopingTest<
|
412
|
+
class BelongsToScopingTest< ActiveRecord::TestCase
|
377
413
|
fixtures :comments, :posts
|
378
414
|
|
379
415
|
def setup
|
@@ -393,7 +429,7 @@ class BelongsToScopingTest< Test::Unit::TestCase
|
|
393
429
|
end
|
394
430
|
|
395
431
|
|
396
|
-
class HasOneScopingTest<
|
432
|
+
class HasOneScopingTest< ActiveRecord::TestCase
|
397
433
|
fixtures :comments, :posts
|
398
434
|
|
399
435
|
def setup
|