activerecord_authorails 1.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.
- data/CHANGELOG +3043 -0
- data/README +360 -0
- data/RUNNING_UNIT_TESTS +64 -0
- data/Rakefile +226 -0
- data/examples/associations.png +0 -0
- data/examples/associations.rb +87 -0
- data/examples/shared_setup.rb +15 -0
- data/examples/validation.rb +85 -0
- data/install.rb +30 -0
- data/lib/active_record.rb +85 -0
- data/lib/active_record/acts/list.rb +244 -0
- data/lib/active_record/acts/nested_set.rb +211 -0
- data/lib/active_record/acts/tree.rb +89 -0
- data/lib/active_record/aggregations.rb +191 -0
- data/lib/active_record/associations.rb +1637 -0
- data/lib/active_record/associations/association_collection.rb +190 -0
- data/lib/active_record/associations/association_proxy.rb +158 -0
- data/lib/active_record/associations/belongs_to_association.rb +56 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +50 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +169 -0
- data/lib/active_record/associations/has_many_association.rb +210 -0
- data/lib/active_record/associations/has_many_through_association.rb +247 -0
- data/lib/active_record/associations/has_one_association.rb +80 -0
- data/lib/active_record/attribute_methods.rb +75 -0
- data/lib/active_record/base.rb +2164 -0
- data/lib/active_record/calculations.rb +270 -0
- data/lib/active_record/callbacks.rb +367 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +279 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +130 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +58 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +343 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +310 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +161 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +228 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +728 -0
- data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +414 -0
- data/lib/active_record/connection_adapters/openbase_adapter.rb +350 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +689 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +584 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +407 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +591 -0
- data/lib/active_record/connection_adapters/sybase_adapter.rb +662 -0
- data/lib/active_record/deprecated_associations.rb +104 -0
- data/lib/active_record/deprecated_finders.rb +44 -0
- data/lib/active_record/fixtures.rb +628 -0
- data/lib/active_record/locking/optimistic.rb +106 -0
- data/lib/active_record/locking/pessimistic.rb +77 -0
- data/lib/active_record/migration.rb +394 -0
- data/lib/active_record/observer.rb +178 -0
- data/lib/active_record/query_cache.rb +64 -0
- data/lib/active_record/reflection.rb +222 -0
- data/lib/active_record/schema.rb +58 -0
- data/lib/active_record/schema_dumper.rb +149 -0
- data/lib/active_record/timestamp.rb +51 -0
- data/lib/active_record/transactions.rb +136 -0
- data/lib/active_record/validations.rb +843 -0
- data/lib/active_record/vendor/db2.rb +362 -0
- data/lib/active_record/vendor/mysql.rb +1214 -0
- data/lib/active_record/vendor/simple.rb +693 -0
- data/lib/active_record/version.rb +9 -0
- data/lib/active_record/wrappers/yaml_wrapper.rb +15 -0
- data/lib/active_record/wrappings.rb +58 -0
- data/lib/active_record/xml_serialization.rb +308 -0
- data/test/aaa_create_tables_test.rb +59 -0
- data/test/abstract_unit.rb +77 -0
- data/test/active_schema_test_mysql.rb +31 -0
- data/test/adapter_test.rb +87 -0
- data/test/adapter_test_sqlserver.rb +81 -0
- data/test/aggregations_test.rb +95 -0
- data/test/all.sh +8 -0
- data/test/ar_schema_test.rb +33 -0
- data/test/association_inheritance_reload.rb +14 -0
- data/test/associations/callbacks_test.rb +126 -0
- data/test/associations/cascaded_eager_loading_test.rb +138 -0
- data/test/associations/eager_test.rb +393 -0
- data/test/associations/extension_test.rb +42 -0
- data/test/associations/join_model_test.rb +497 -0
- data/test/associations_test.rb +1809 -0
- data/test/attribute_methods_test.rb +49 -0
- data/test/base_test.rb +1586 -0
- data/test/binary_test.rb +37 -0
- data/test/calculations_test.rb +219 -0
- data/test/callbacks_test.rb +377 -0
- data/test/class_inheritable_attributes_test.rb +32 -0
- data/test/column_alias_test.rb +17 -0
- data/test/connection_test_firebird.rb +8 -0
- data/test/connections/native_db2/connection.rb +25 -0
- data/test/connections/native_firebird/connection.rb +26 -0
- data/test/connections/native_frontbase/connection.rb +27 -0
- data/test/connections/native_mysql/connection.rb +24 -0
- data/test/connections/native_openbase/connection.rb +21 -0
- data/test/connections/native_oracle/connection.rb +27 -0
- data/test/connections/native_postgresql/connection.rb +23 -0
- data/test/connections/native_sqlite/connection.rb +34 -0
- data/test/connections/native_sqlite3/connection.rb +34 -0
- data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
- data/test/connections/native_sqlserver/connection.rb +23 -0
- data/test/connections/native_sqlserver_odbc/connection.rb +25 -0
- data/test/connections/native_sybase/connection.rb +23 -0
- data/test/copy_table_sqlite.rb +64 -0
- data/test/datatype_test_postgresql.rb +52 -0
- data/test/default_test_firebird.rb +16 -0
- data/test/defaults_test.rb +60 -0
- data/test/deprecated_associations_test.rb +396 -0
- data/test/deprecated_finder_test.rb +151 -0
- data/test/empty_date_time_test.rb +25 -0
- data/test/finder_test.rb +504 -0
- data/test/fixtures/accounts.yml +28 -0
- data/test/fixtures/author.rb +99 -0
- data/test/fixtures/author_favorites.yml +4 -0
- data/test/fixtures/authors.yml +7 -0
- data/test/fixtures/auto_id.rb +4 -0
- data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +1 -0
- data/test/fixtures/bad_fixtures/attr_with_spaces +1 -0
- data/test/fixtures/bad_fixtures/blank_line +3 -0
- data/test/fixtures/bad_fixtures/duplicate_attributes +3 -0
- data/test/fixtures/bad_fixtures/missing_value +1 -0
- data/test/fixtures/binary.rb +2 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/categories/special_categories.yml +9 -0
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/test/fixtures/categories_ordered.yml +7 -0
- data/test/fixtures/categories_posts.yml +23 -0
- data/test/fixtures/categorization.rb +5 -0
- data/test/fixtures/categorizations.yml +17 -0
- data/test/fixtures/category.rb +20 -0
- data/test/fixtures/column_name.rb +3 -0
- data/test/fixtures/comment.rb +23 -0
- data/test/fixtures/comments.yml +59 -0
- data/test/fixtures/companies.yml +55 -0
- data/test/fixtures/company.rb +107 -0
- data/test/fixtures/company_in_module.rb +59 -0
- data/test/fixtures/computer.rb +3 -0
- data/test/fixtures/computers.yml +4 -0
- data/test/fixtures/course.rb +3 -0
- data/test/fixtures/courses.yml +7 -0
- data/test/fixtures/customer.rb +55 -0
- data/test/fixtures/customers.yml +17 -0
- data/test/fixtures/db_definitions/db2.drop.sql +32 -0
- data/test/fixtures/db_definitions/db2.sql +231 -0
- data/test/fixtures/db_definitions/db22.drop.sql +2 -0
- data/test/fixtures/db_definitions/db22.sql +5 -0
- data/test/fixtures/db_definitions/firebird.drop.sql +63 -0
- data/test/fixtures/db_definitions/firebird.sql +304 -0
- data/test/fixtures/db_definitions/firebird2.drop.sql +2 -0
- data/test/fixtures/db_definitions/firebird2.sql +6 -0
- data/test/fixtures/db_definitions/frontbase.drop.sql +32 -0
- data/test/fixtures/db_definitions/frontbase.sql +268 -0
- data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
- data/test/fixtures/db_definitions/frontbase2.sql +4 -0
- data/test/fixtures/db_definitions/mysql.drop.sql +32 -0
- data/test/fixtures/db_definitions/mysql.sql +234 -0
- data/test/fixtures/db_definitions/mysql2.drop.sql +2 -0
- data/test/fixtures/db_definitions/mysql2.sql +5 -0
- data/test/fixtures/db_definitions/openbase.drop.sql +2 -0
- data/test/fixtures/db_definitions/openbase.sql +302 -0
- data/test/fixtures/db_definitions/openbase2.drop.sql +2 -0
- data/test/fixtures/db_definitions/openbase2.sql +7 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +65 -0
- data/test/fixtures/db_definitions/oracle.sql +325 -0
- data/test/fixtures/db_definitions/oracle2.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle2.sql +6 -0
- data/test/fixtures/db_definitions/postgresql.drop.sql +37 -0
- data/test/fixtures/db_definitions/postgresql.sql +263 -0
- data/test/fixtures/db_definitions/postgresql2.drop.sql +2 -0
- data/test/fixtures/db_definitions/postgresql2.sql +5 -0
- data/test/fixtures/db_definitions/schema.rb +60 -0
- data/test/fixtures/db_definitions/sqlite.drop.sql +32 -0
- data/test/fixtures/db_definitions/sqlite.sql +215 -0
- data/test/fixtures/db_definitions/sqlite2.drop.sql +2 -0
- data/test/fixtures/db_definitions/sqlite2.sql +5 -0
- data/test/fixtures/db_definitions/sqlserver.drop.sql +34 -0
- data/test/fixtures/db_definitions/sqlserver.sql +243 -0
- data/test/fixtures/db_definitions/sqlserver2.drop.sql +2 -0
- data/test/fixtures/db_definitions/sqlserver2.sql +5 -0
- data/test/fixtures/db_definitions/sybase.drop.sql +34 -0
- data/test/fixtures/db_definitions/sybase.sql +218 -0
- data/test/fixtures/db_definitions/sybase2.drop.sql +4 -0
- data/test/fixtures/db_definitions/sybase2.sql +5 -0
- data/test/fixtures/default.rb +2 -0
- data/test/fixtures/developer.rb +52 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +17 -0
- data/test/fixtures/developers_projects/david_action_controller +3 -0
- data/test/fixtures/developers_projects/david_active_record +3 -0
- data/test/fixtures/developers_projects/jamis_active_record +2 -0
- data/test/fixtures/edge.rb +5 -0
- data/test/fixtures/edges.yml +6 -0
- data/test/fixtures/entrant.rb +3 -0
- data/test/fixtures/entrants.yml +14 -0
- data/test/fixtures/fk_test_has_fk.yml +3 -0
- data/test/fixtures/fk_test_has_pk.yml +2 -0
- data/test/fixtures/flowers.jpg +0 -0
- data/test/fixtures/funny_jokes.yml +10 -0
- data/test/fixtures/joke.rb +6 -0
- data/test/fixtures/keyboard.rb +3 -0
- data/test/fixtures/legacy_thing.rb +3 -0
- data/test/fixtures/legacy_things.yml +3 -0
- data/test/fixtures/migrations/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations/2_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
- data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
- data/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_duplicate/2_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_duplicate/3_foo.rb +7 -0
- data/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
- data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
- data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
- data/test/fixtures/mixed_case_monkey.rb +3 -0
- data/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/test/fixtures/mixin.rb +63 -0
- data/test/fixtures/mixins.yml +127 -0
- data/test/fixtures/movie.rb +5 -0
- data/test/fixtures/movies.yml +7 -0
- data/test/fixtures/naked/csv/accounts.csv +1 -0
- data/test/fixtures/naked/yml/accounts.yml +1 -0
- data/test/fixtures/naked/yml/companies.yml +1 -0
- data/test/fixtures/naked/yml/courses.yml +1 -0
- data/test/fixtures/order.rb +4 -0
- data/test/fixtures/people.yml +3 -0
- data/test/fixtures/person.rb +4 -0
- data/test/fixtures/post.rb +58 -0
- data/test/fixtures/posts.yml +48 -0
- data/test/fixtures/project.rb +27 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/reader.rb +4 -0
- data/test/fixtures/readers.yml +4 -0
- data/test/fixtures/reply.rb +37 -0
- data/test/fixtures/subject.rb +4 -0
- data/test/fixtures/subscriber.rb +6 -0
- data/test/fixtures/subscribers/first +2 -0
- data/test/fixtures/subscribers/second +2 -0
- data/test/fixtures/tag.rb +7 -0
- data/test/fixtures/tagging.rb +6 -0
- data/test/fixtures/taggings.yml +18 -0
- data/test/fixtures/tags.yml +7 -0
- data/test/fixtures/task.rb +3 -0
- data/test/fixtures/tasks.yml +7 -0
- data/test/fixtures/topic.rb +25 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/fixtures/vertex.rb +9 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures_test.rb +401 -0
- data/test/inheritance_test.rb +205 -0
- data/test/lifecycle_test.rb +137 -0
- data/test/locking_test.rb +190 -0
- data/test/method_scoping_test.rb +416 -0
- data/test/migration_test.rb +768 -0
- data/test/migration_test_firebird.rb +124 -0
- data/test/mixin_nested_set_test.rb +196 -0
- data/test/mixin_test.rb +550 -0
- data/test/modules_test.rb +34 -0
- data/test/multiple_db_test.rb +60 -0
- data/test/pk_test.rb +104 -0
- data/test/readonly_test.rb +107 -0
- data/test/reflection_test.rb +159 -0
- data/test/schema_authorization_test_postgresql.rb +75 -0
- data/test/schema_dumper_test.rb +96 -0
- data/test/schema_test_postgresql.rb +64 -0
- data/test/synonym_test_oracle.rb +17 -0
- data/test/table_name_test_sqlserver.rb +23 -0
- data/test/threaded_connections_test.rb +48 -0
- data/test/transactions_test.rb +230 -0
- data/test/unconnected_test.rb +32 -0
- data/test/validations_test.rb +1097 -0
- data/test/xml_serialization_test.rb +125 -0
- metadata +365 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/company_in_module'
|
|
3
|
+
|
|
4
|
+
class ModulesTest < Test::Unit::TestCase
|
|
5
|
+
fixtures :accounts, :companies, :projects, :developers
|
|
6
|
+
|
|
7
|
+
def test_module_spanning_associations
|
|
8
|
+
firm = MyApplication::Business::Firm.find(:first)
|
|
9
|
+
assert !firm.clients.empty?, "Firm should have clients"
|
|
10
|
+
assert_nil firm.class.table_name.match('::'), "Firm shouldn't have the module appear in its table name"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_module_spanning_has_and_belongs_to_many_associations
|
|
14
|
+
project = MyApplication::Business::Project.find(:first)
|
|
15
|
+
project.developers << MyApplication::Business::Developer.create("name" => "John")
|
|
16
|
+
assert "John", project.developers.last.name
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_associations_spanning_cross_modules
|
|
20
|
+
account = MyApplication::Billing::Account.find(:first, :order => 'id')
|
|
21
|
+
assert_kind_of MyApplication::Business::Firm, account.firm
|
|
22
|
+
assert_kind_of MyApplication::Billing::Firm, account.qualified_billing_firm
|
|
23
|
+
assert_kind_of MyApplication::Billing::Firm, account.unqualified_billing_firm
|
|
24
|
+
assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_qualified_billing_firm
|
|
25
|
+
assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_unqualified_billing_firm
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_find_account_and_include_company
|
|
29
|
+
account = MyApplication::Billing::Account.find(1, :include => :firm)
|
|
30
|
+
assert_kind_of MyApplication::Business::Firm, account.instance_variable_get('@firm')
|
|
31
|
+
assert_kind_of MyApplication::Business::Firm, account.firm
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/entrant'
|
|
3
|
+
|
|
4
|
+
# So we can test whether Course.connection survives a reload.
|
|
5
|
+
require_dependency 'fixtures/course'
|
|
6
|
+
|
|
7
|
+
class MultipleDbTest < Test::Unit::TestCase
|
|
8
|
+
self.use_transactional_fixtures = false
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
@courses = create_fixtures("courses") { Course.retrieve_connection }
|
|
12
|
+
@entrants = create_fixtures("entrants")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_connected
|
|
16
|
+
assert_not_nil Entrant.connection
|
|
17
|
+
assert_not_nil Course.connection
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_proper_connection
|
|
21
|
+
assert_not_equal(Entrant.connection, Course.connection)
|
|
22
|
+
assert_equal(Entrant.connection, Entrant.retrieve_connection)
|
|
23
|
+
assert_equal(Course.connection, Course.retrieve_connection)
|
|
24
|
+
assert_equal(ActiveRecord::Base.connection, Entrant.connection)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_find
|
|
28
|
+
c1 = Course.find(1)
|
|
29
|
+
assert_equal "Ruby Development", c1.name
|
|
30
|
+
c2 = Course.find(2)
|
|
31
|
+
assert_equal "Java Development", c2.name
|
|
32
|
+
e1 = Entrant.find(1)
|
|
33
|
+
assert_equal "Ruby Developer", e1.name
|
|
34
|
+
e2 = Entrant.find(2)
|
|
35
|
+
assert_equal "Ruby Guru", e2.name
|
|
36
|
+
e3 = Entrant.find(3)
|
|
37
|
+
assert_equal "Java Lover", e3.name
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_associations
|
|
41
|
+
c1 = Course.find(1)
|
|
42
|
+
assert_equal 2, c1.entrants.count
|
|
43
|
+
e1 = Entrant.find(1)
|
|
44
|
+
assert_equal e1.course.id, c1.id
|
|
45
|
+
c2 = Course.find(2)
|
|
46
|
+
assert_equal 1, c2.entrants.count
|
|
47
|
+
e3 = Entrant.find(3)
|
|
48
|
+
assert_equal e3.course.id, c2.id
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_course_connection_should_survive_dependency_reload
|
|
52
|
+
assert Course.connection
|
|
53
|
+
|
|
54
|
+
Dependencies.clear
|
|
55
|
+
Object.send(:remove_const, :Course)
|
|
56
|
+
require_dependency 'fixtures/course'
|
|
57
|
+
|
|
58
|
+
assert Course.connection
|
|
59
|
+
end
|
|
60
|
+
end
|
data/test/pk_test.rb
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require "#{File.dirname(__FILE__)}/abstract_unit"
|
|
2
|
+
require 'fixtures/topic'
|
|
3
|
+
require 'fixtures/reply'
|
|
4
|
+
require 'fixtures/subscriber'
|
|
5
|
+
require 'fixtures/movie'
|
|
6
|
+
require 'fixtures/keyboard'
|
|
7
|
+
require 'fixtures/mixed_case_monkey'
|
|
8
|
+
|
|
9
|
+
class PrimaryKeysTest < Test::Unit::TestCase
|
|
10
|
+
fixtures :topics, :subscribers, :movies, :mixed_case_monkeys
|
|
11
|
+
|
|
12
|
+
def test_integer_key
|
|
13
|
+
topic = Topic.find(1)
|
|
14
|
+
assert_equal(topics(:first).author_name, topic.author_name)
|
|
15
|
+
topic = Topic.find(2)
|
|
16
|
+
assert_equal(topics(:second).author_name, topic.author_name)
|
|
17
|
+
|
|
18
|
+
topic = Topic.new
|
|
19
|
+
topic.title = "New Topic"
|
|
20
|
+
assert_equal(nil, topic.id)
|
|
21
|
+
assert_nothing_raised { topic.save! }
|
|
22
|
+
id = topic.id
|
|
23
|
+
|
|
24
|
+
topicReloaded = Topic.find(id)
|
|
25
|
+
assert_equal("New Topic", topicReloaded.title)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_customized_primary_key_auto_assigns_on_save
|
|
29
|
+
Keyboard.delete_all
|
|
30
|
+
keyboard = Keyboard.new(:name => 'HHKB')
|
|
31
|
+
assert_nothing_raised { keyboard.save! }
|
|
32
|
+
assert_equal keyboard.id, Keyboard.find_by_name('HHKB').id
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_customized_primary_key_can_be_get_before_saving
|
|
36
|
+
keyboard = Keyboard.new
|
|
37
|
+
assert_nil keyboard.id
|
|
38
|
+
assert_nothing_raised { assert_nil keyboard.key_number }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_customized_string_primary_key_settable_before_save
|
|
42
|
+
subscriber = Subscriber.new
|
|
43
|
+
assert_nothing_raised { subscriber.id = 'webster123' }
|
|
44
|
+
assert_equal 'webster123', subscriber.id
|
|
45
|
+
assert_equal 'webster123', subscriber.nick
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_string_key
|
|
49
|
+
subscriber = Subscriber.find(subscribers(:first).nick)
|
|
50
|
+
assert_equal(subscribers(:first).name, subscriber.name)
|
|
51
|
+
subscriber = Subscriber.find(subscribers(:second).nick)
|
|
52
|
+
assert_equal(subscribers(:second).name, subscriber.name)
|
|
53
|
+
|
|
54
|
+
subscriber = Subscriber.new
|
|
55
|
+
subscriber.id = "jdoe"
|
|
56
|
+
assert_equal("jdoe", subscriber.id)
|
|
57
|
+
subscriber.name = "John Doe"
|
|
58
|
+
assert_nothing_raised { subscriber.save! }
|
|
59
|
+
assert_equal("jdoe", subscriber.id)
|
|
60
|
+
|
|
61
|
+
subscriberReloaded = Subscriber.find("jdoe")
|
|
62
|
+
assert_equal("John Doe", subscriberReloaded.name)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_find_with_more_than_one_string_key
|
|
66
|
+
assert_equal 2, Subscriber.find(subscribers(:first).nick, subscribers(:second).nick).length
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_primary_key_prefix
|
|
70
|
+
ActiveRecord::Base.primary_key_prefix_type = :table_name
|
|
71
|
+
Topic.reset_primary_key
|
|
72
|
+
assert_equal "topicid", Topic.primary_key
|
|
73
|
+
|
|
74
|
+
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
|
|
75
|
+
Topic.reset_primary_key
|
|
76
|
+
assert_equal "topic_id", Topic.primary_key
|
|
77
|
+
|
|
78
|
+
ActiveRecord::Base.primary_key_prefix_type = nil
|
|
79
|
+
Topic.reset_primary_key
|
|
80
|
+
assert_equal "id", Topic.primary_key
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_delete_should_quote_pkey
|
|
84
|
+
assert_nothing_raised { MixedCaseMonkey.delete(1) }
|
|
85
|
+
end
|
|
86
|
+
def test_increment_counter_should_quote_pkey_and_quote_counter_columns
|
|
87
|
+
assert_nothing_raised { MixedCaseMonkey.increment_counter(:fleaCount, 1) }
|
|
88
|
+
end
|
|
89
|
+
def test_decrement_counter_should_quote_pkey_and_quote_counter_columns
|
|
90
|
+
assert_nothing_raised { MixedCaseMonkey.decrement_counter(:fleaCount, 1) }
|
|
91
|
+
end
|
|
92
|
+
def test_find_with_one_id_should_quote_pkey
|
|
93
|
+
assert_nothing_raised { MixedCaseMonkey.find(1) }
|
|
94
|
+
end
|
|
95
|
+
def test_find_with_multiple_ids_should_quote_pkey
|
|
96
|
+
assert_nothing_raised { MixedCaseMonkey.find([1,2]) }
|
|
97
|
+
end
|
|
98
|
+
def test_instance_update_should_quote_pkey
|
|
99
|
+
assert_nothing_raised { MixedCaseMonkey.find(1).save }
|
|
100
|
+
end
|
|
101
|
+
def test_instance_destry_should_quote_pkey
|
|
102
|
+
assert_nothing_raised { MixedCaseMonkey.find(1).destroy }
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/post'
|
|
3
|
+
require 'fixtures/comment'
|
|
4
|
+
require 'fixtures/developer'
|
|
5
|
+
require 'fixtures/project'
|
|
6
|
+
require 'fixtures/reader'
|
|
7
|
+
require 'fixtures/person'
|
|
8
|
+
|
|
9
|
+
# Dummy class methods to test implicit association scoping.
|
|
10
|
+
def Comment.foo() find :first end
|
|
11
|
+
def Project.foo() find :first end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ReadOnlyTest < Test::Unit::TestCase
|
|
15
|
+
fixtures :posts, :comments, :developers, :projects, :developers_projects
|
|
16
|
+
|
|
17
|
+
def test_cant_save_readonly_record
|
|
18
|
+
dev = Developer.find(1)
|
|
19
|
+
assert !dev.readonly?
|
|
20
|
+
|
|
21
|
+
dev.readonly!
|
|
22
|
+
assert dev.readonly?
|
|
23
|
+
|
|
24
|
+
assert_nothing_raised do
|
|
25
|
+
dev.name = 'Luscious forbidden fruit.'
|
|
26
|
+
assert !dev.save
|
|
27
|
+
dev.name = 'Forbidden.'
|
|
28
|
+
end
|
|
29
|
+
assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save }
|
|
30
|
+
assert_raise(ActiveRecord::ReadOnlyRecord) { dev.save! }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_find_with_readonly_option
|
|
35
|
+
Developer.find(:all).each { |d| assert !d.readonly? }
|
|
36
|
+
Developer.find(:all, :readonly => false).each { |d| assert !d.readonly? }
|
|
37
|
+
Developer.find(:all, :readonly => true).each { |d| assert d.readonly? }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_find_with_joins_option_implies_readonly
|
|
42
|
+
# Blank joins don't count.
|
|
43
|
+
Developer.find(:all, :joins => ' ').each { |d| assert !d.readonly? }
|
|
44
|
+
Developer.find(:all, :joins => ' ', :readonly => false).each { |d| assert !d.readonly? }
|
|
45
|
+
|
|
46
|
+
# Others do.
|
|
47
|
+
Developer.find(:all, :joins => ', projects').each { |d| assert d.readonly? }
|
|
48
|
+
Developer.find(:all, :joins => ', projects', :readonly => false).each { |d| assert !d.readonly? }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_habtm_find_readonly
|
|
53
|
+
dev = Developer.find(1)
|
|
54
|
+
assert !dev.projects.empty?
|
|
55
|
+
assert dev.projects.all?(&:readonly?)
|
|
56
|
+
assert dev.projects.find(:all).all?(&:readonly?)
|
|
57
|
+
assert dev.projects.find(:all, :readonly => true).all?(&:readonly?)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_has_many_find_readonly
|
|
61
|
+
post = Post.find(1)
|
|
62
|
+
assert !post.comments.empty?
|
|
63
|
+
assert !post.comments.any?(&:readonly?)
|
|
64
|
+
assert !post.comments.find(:all).any?(&:readonly?)
|
|
65
|
+
assert post.comments.find(:all, :readonly => true).all?(&:readonly?)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_has_many_with_through_is_not_implicitly_marked_readonly
|
|
69
|
+
assert people = Post.find(1).people
|
|
70
|
+
assert !people.any?(&:readonly?)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_readonly_scoping
|
|
74
|
+
Post.with_scope(:find => { :conditions => '1=1' }) do
|
|
75
|
+
assert !Post.find(1).readonly?
|
|
76
|
+
assert Post.find(1, :readonly => true).readonly?
|
|
77
|
+
assert !Post.find(1, :readonly => false).readonly?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
Post.with_scope(:find => { :joins => ' ' }) do
|
|
81
|
+
assert !Post.find(1).readonly?
|
|
82
|
+
assert Post.find(1, :readonly => true).readonly?
|
|
83
|
+
assert !Post.find(1, :readonly => false).readonly?
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Oracle barfs on this because the join includes unqualified and
|
|
87
|
+
# conflicting column names
|
|
88
|
+
unless current_adapter?(:OracleAdapter)
|
|
89
|
+
Post.with_scope(:find => { :joins => ', developers' }) do
|
|
90
|
+
assert Post.find(1).readonly?
|
|
91
|
+
assert Post.find(1, :readonly => true).readonly?
|
|
92
|
+
assert !Post.find(1, :readonly => false).readonly?
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
Post.with_scope(:find => { :readonly => true }) do
|
|
97
|
+
assert Post.find(1).readonly?
|
|
98
|
+
assert Post.find(1, :readonly => true).readonly?
|
|
99
|
+
assert !Post.find(1, :readonly => false).readonly?
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_association_collection_method_missing_scoping_not_readonly
|
|
104
|
+
assert !Developer.find(1).projects.foo.readonly?
|
|
105
|
+
assert !Post.find(1).comments.foo.readonly?
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/topic'
|
|
3
|
+
require 'fixtures/customer'
|
|
4
|
+
require 'fixtures/company'
|
|
5
|
+
require 'fixtures/company_in_module'
|
|
6
|
+
require 'fixtures/subscriber'
|
|
7
|
+
|
|
8
|
+
class ReflectionTest < Test::Unit::TestCase
|
|
9
|
+
fixtures :topics, :customers, :companies, :subscribers
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
@first = Topic.find(1)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_column_null_not_null
|
|
16
|
+
subscriber = Subscriber.find(:first)
|
|
17
|
+
assert subscriber.column_for_attribute("name").null
|
|
18
|
+
assert !subscriber.column_for_attribute("nick").null
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_read_attribute_names
|
|
22
|
+
assert_equal(
|
|
23
|
+
%w( id title author_name author_email_address bonus_time written_on last_read content approved replies_count parent_id type ).sort,
|
|
24
|
+
@first.attribute_names
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_columns
|
|
29
|
+
assert_equal 12, Topic.columns.length
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_columns_are_returned_in_the_order_they_were_declared
|
|
33
|
+
column_names = Topic.columns.map { |column| column.name }
|
|
34
|
+
assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content approved replies_count parent_id type), column_names
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_content_columns
|
|
38
|
+
content_columns = Topic.content_columns
|
|
39
|
+
content_column_names = content_columns.map {|column| column.name}
|
|
40
|
+
assert_equal 8, content_columns.length
|
|
41
|
+
assert_equal %w(title author_name author_email_address written_on bonus_time last_read content approved).sort, content_column_names.sort
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_column_string_type_and_limit
|
|
45
|
+
assert_equal :string, @first.column_for_attribute("title").type
|
|
46
|
+
assert_equal 255, @first.column_for_attribute("title").limit
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_column_null_not_null
|
|
50
|
+
subscriber = Subscriber.find(:first)
|
|
51
|
+
assert subscriber.column_for_attribute("name").null
|
|
52
|
+
assert !subscriber.column_for_attribute("nick").null
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_human_name_for_column
|
|
56
|
+
assert_equal "Author name", @first.column_for_attribute("author_name").human_name
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_integer_columns
|
|
60
|
+
assert_equal :integer, @first.column_for_attribute("id").type
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_aggregation_reflection
|
|
64
|
+
reflection_for_address = ActiveRecord::Reflection::AggregateReflection.new(
|
|
65
|
+
:composed_of, :address, { :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ] }, Customer
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
reflection_for_balance = ActiveRecord::Reflection::AggregateReflection.new(
|
|
69
|
+
:composed_of, :balance, { :class_name => "Money", :mapping => %w(balance amount) }, Customer
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
reflection_for_gps_location = ActiveRecord::Reflection::AggregateReflection.new(
|
|
73
|
+
:composed_of, :gps_location, { }, Customer
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
assert Customer.reflect_on_all_aggregations.include?(reflection_for_gps_location)
|
|
77
|
+
assert Customer.reflect_on_all_aggregations.include?(reflection_for_balance)
|
|
78
|
+
assert Customer.reflect_on_all_aggregations.include?(reflection_for_address)
|
|
79
|
+
|
|
80
|
+
assert_equal reflection_for_address, Customer.reflect_on_aggregation(:address)
|
|
81
|
+
|
|
82
|
+
assert_equal Address, Customer.reflect_on_aggregation(:address).klass
|
|
83
|
+
|
|
84
|
+
assert_equal Money, Customer.reflect_on_aggregation(:balance).klass
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_has_many_reflection
|
|
88
|
+
reflection_for_clients = ActiveRecord::Reflection::AssociationReflection.new(:has_many, :clients, { :order => "id", :dependent => :destroy }, Firm)
|
|
89
|
+
|
|
90
|
+
assert_equal reflection_for_clients, Firm.reflect_on_association(:clients)
|
|
91
|
+
|
|
92
|
+
assert_equal Client, Firm.reflect_on_association(:clients).klass
|
|
93
|
+
assert_equal 'companies', Firm.reflect_on_association(:clients).table_name
|
|
94
|
+
|
|
95
|
+
assert_equal Client, Firm.reflect_on_association(:clients_of_firm).klass
|
|
96
|
+
assert_equal 'companies', Firm.reflect_on_association(:clients_of_firm).table_name
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_has_one_reflection
|
|
100
|
+
reflection_for_account = ActiveRecord::Reflection::AssociationReflection.new(:has_one, :account, { :foreign_key => "firm_id", :dependent => :destroy }, Firm)
|
|
101
|
+
assert_equal reflection_for_account, Firm.reflect_on_association(:account)
|
|
102
|
+
|
|
103
|
+
assert_equal Account, Firm.reflect_on_association(:account).klass
|
|
104
|
+
assert_equal 'accounts', Firm.reflect_on_association(:account).table_name
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_association_reflection_in_modules
|
|
108
|
+
assert_reflection MyApplication::Business::Firm,
|
|
109
|
+
:clients_of_firm,
|
|
110
|
+
:klass => MyApplication::Business::Client,
|
|
111
|
+
:class_name => 'Client',
|
|
112
|
+
:table_name => 'companies'
|
|
113
|
+
|
|
114
|
+
assert_reflection MyApplication::Billing::Account,
|
|
115
|
+
:firm,
|
|
116
|
+
:klass => MyApplication::Business::Firm,
|
|
117
|
+
:class_name => 'MyApplication::Business::Firm',
|
|
118
|
+
:table_name => 'companies'
|
|
119
|
+
|
|
120
|
+
assert_reflection MyApplication::Billing::Account,
|
|
121
|
+
:qualified_billing_firm,
|
|
122
|
+
:klass => MyApplication::Billing::Firm,
|
|
123
|
+
:class_name => 'MyApplication::Billing::Firm',
|
|
124
|
+
:table_name => 'companies'
|
|
125
|
+
|
|
126
|
+
assert_reflection MyApplication::Billing::Account,
|
|
127
|
+
:unqualified_billing_firm,
|
|
128
|
+
:klass => MyApplication::Billing::Firm,
|
|
129
|
+
:class_name => 'Firm',
|
|
130
|
+
:table_name => 'companies'
|
|
131
|
+
|
|
132
|
+
assert_reflection MyApplication::Billing::Account,
|
|
133
|
+
:nested_qualified_billing_firm,
|
|
134
|
+
:klass => MyApplication::Billing::Nested::Firm,
|
|
135
|
+
:class_name => 'MyApplication::Billing::Nested::Firm',
|
|
136
|
+
:table_name => 'companies'
|
|
137
|
+
|
|
138
|
+
assert_reflection MyApplication::Billing::Account,
|
|
139
|
+
:nested_unqualified_billing_firm,
|
|
140
|
+
:klass => MyApplication::Billing::Nested::Firm,
|
|
141
|
+
:class_name => 'Nested::Firm',
|
|
142
|
+
:table_name => 'companies'
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_reflection_of_all_associations
|
|
146
|
+
assert_equal 17, Firm.reflect_on_all_associations.size
|
|
147
|
+
assert_equal 15, Firm.reflect_on_all_associations(:has_many).size
|
|
148
|
+
assert_equal 2, Firm.reflect_on_all_associations(:has_one).size
|
|
149
|
+
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
def assert_reflection(klass, association, options)
|
|
154
|
+
assert reflection = klass.reflect_on_association(association)
|
|
155
|
+
options.each do |method, value|
|
|
156
|
+
assert_equal(value, reflection.send(method))
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|