activerecord_authorails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,52 @@
|
|
1
|
+
module DeveloperProjectsAssociationExtension
|
2
|
+
def find_most_recent
|
3
|
+
find(:first, :order => "id DESC")
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module DeveloperProjectsAssociationExtension2
|
8
|
+
def find_least_recent
|
9
|
+
find(:first, :order => "id ASC")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Developer < ActiveRecord::Base
|
14
|
+
has_and_belongs_to_many :projects do
|
15
|
+
def find_most_recent
|
16
|
+
find(:first, :order => "id DESC")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
has_and_belongs_to_many :projects_extended_by_name,
|
21
|
+
:class_name => "Project",
|
22
|
+
:join_table => "developers_projects",
|
23
|
+
:association_foreign_key => "project_id",
|
24
|
+
:extend => DeveloperProjectsAssociationExtension
|
25
|
+
|
26
|
+
has_and_belongs_to_many :projects_extended_by_name_twice,
|
27
|
+
:class_name => "Project",
|
28
|
+
:join_table => "developers_projects",
|
29
|
+
:association_foreign_key => "project_id",
|
30
|
+
:extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
|
31
|
+
|
32
|
+
has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
|
33
|
+
|
34
|
+
validates_inclusion_of :salary, :in => 50000..200000
|
35
|
+
validates_length_of :name, :within => 3..20
|
36
|
+
end
|
37
|
+
|
38
|
+
DeveloperSalary = Struct.new(:amount)
|
39
|
+
class DeveloperWithAggregate < ActiveRecord::Base
|
40
|
+
self.table_name = 'developers'
|
41
|
+
composed_of :salary, :class_name => 'DeveloperSalary', :mapping => [%w(salary amount)]
|
42
|
+
end
|
43
|
+
|
44
|
+
class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base
|
45
|
+
self.table_name = 'developers'
|
46
|
+
has_and_belongs_to_many :projects, :join_table => 'developers_projects', :foreign_key => 'developer_id'
|
47
|
+
before_destroy :raise_if_projects_empty!
|
48
|
+
|
49
|
+
def raise_if_projects_empty!
|
50
|
+
raise if projects.empty?
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
david:
|
2
|
+
id: 1
|
3
|
+
name: David
|
4
|
+
salary: 80000
|
5
|
+
|
6
|
+
jamis:
|
7
|
+
id: 2
|
8
|
+
name: Jamis
|
9
|
+
salary: 150000
|
10
|
+
|
11
|
+
<% for digit in 3..10 %>
|
12
|
+
dev_<%= digit %>:
|
13
|
+
id: <%= digit %>
|
14
|
+
name: fixture_<%= digit %>
|
15
|
+
salary: 100000
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
poor_jamis:
|
19
|
+
id: 11
|
20
|
+
name: Jamis
|
21
|
+
salary: 9000
|
@@ -0,0 +1,17 @@
|
|
1
|
+
david_action_controller:
|
2
|
+
developer_id: 1
|
3
|
+
project_id: 2
|
4
|
+
joined_on: 2004-10-10
|
5
|
+
|
6
|
+
david_active_record:
|
7
|
+
developer_id: 1
|
8
|
+
project_id: 1
|
9
|
+
joined_on: 2004-10-10
|
10
|
+
|
11
|
+
jamis_active_record:
|
12
|
+
developer_id: 2
|
13
|
+
project_id: 1
|
14
|
+
|
15
|
+
poor_jamis_active_record:
|
16
|
+
developer_id: 11
|
17
|
+
project_id: 1
|
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class InnocentJointable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table("people_reminders", :id => false) do |t|
|
4
|
+
t.column :reminder_id, :integer
|
5
|
+
t.column :person_id, :integer
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
drop_table "people_reminders"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class GiveMeBigNumbers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :big_numbers do |table|
|
4
|
+
table.column :bank_balance, :decimal, :precision => 10, :scale => 2
|
5
|
+
table.column :big_bank_balance, :decimal, :precision => 15, :scale => 2
|
6
|
+
table.column :world_population, :decimal, :precision => 10
|
7
|
+
table.column :my_house_population, :decimal, :precision => 2
|
8
|
+
table.column :value_of_e, :decimal
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :big_numbers
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class InnocentJointable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table("people_reminders", :id => false) do |t|
|
4
|
+
t.column :reminder_id, :integer
|
5
|
+
t.column :person_id, :integer
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
drop_table "people_reminders"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class InnocentJointable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table("people_reminders", :id => false) do |t|
|
4
|
+
t.column :reminder_id, :integer
|
5
|
+
t.column :person_id, :integer
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
drop_table "people_reminders"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Mixin < ActiveRecord::Base
|
2
|
+
|
3
|
+
end
|
4
|
+
|
5
|
+
class TreeMixin < Mixin
|
6
|
+
acts_as_tree :foreign_key => "parent_id", :order => "id"
|
7
|
+
end
|
8
|
+
|
9
|
+
class TreeMixinWithoutOrder < Mixin
|
10
|
+
acts_as_tree :foreign_key => "parent_id"
|
11
|
+
end
|
12
|
+
|
13
|
+
class RecursivelyCascadedTreeMixin < Mixin
|
14
|
+
acts_as_tree :foreign_key => "parent_id"
|
15
|
+
has_one :first_child, :class_name => 'RecursivelyCascadedTreeMixin', :foreign_key => :parent_id
|
16
|
+
end
|
17
|
+
|
18
|
+
class ListMixin < Mixin
|
19
|
+
acts_as_list :column => "pos", :scope => :parent
|
20
|
+
|
21
|
+
def self.table_name() "mixins" end
|
22
|
+
end
|
23
|
+
|
24
|
+
class ListMixinSub1 < ListMixin
|
25
|
+
end
|
26
|
+
|
27
|
+
class ListMixinSub2 < ListMixin
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
class ListWithStringScopeMixin < ActiveRecord::Base
|
32
|
+
acts_as_list :column => "pos", :scope => 'parent_id = #{parent_id}'
|
33
|
+
|
34
|
+
def self.table_name() "mixins" end
|
35
|
+
end
|
36
|
+
|
37
|
+
class NestedSet < Mixin
|
38
|
+
acts_as_nested_set :scope => "root_id IS NULL"
|
39
|
+
|
40
|
+
def self.table_name() "mixins" end
|
41
|
+
end
|
42
|
+
|
43
|
+
class NestedSetWithStringScope < Mixin
|
44
|
+
acts_as_nested_set :scope => 'root_id = #{root_id}'
|
45
|
+
|
46
|
+
def self.table_name() "mixins" end
|
47
|
+
end
|
48
|
+
|
49
|
+
class NestedSetWithSymbolScope < Mixin
|
50
|
+
acts_as_nested_set :scope => :root
|
51
|
+
|
52
|
+
def self.table_name() "mixins" end
|
53
|
+
end
|
54
|
+
|
55
|
+
class NestedSetSuperclass < Mixin
|
56
|
+
acts_as_nested_set :scope => :root
|
57
|
+
|
58
|
+
def self.table_name() "mixins" end
|
59
|
+
end
|
60
|
+
|
61
|
+
class NestedSetSubclass < NestedSetSuperclass
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# tree mixins
|
2
|
+
tree_1:
|
3
|
+
id: 1001
|
4
|
+
type: TreeMixin
|
5
|
+
parent_id:
|
6
|
+
|
7
|
+
tree_2:
|
8
|
+
id: 1002
|
9
|
+
type: TreeMixin
|
10
|
+
parent_id: 1001
|
11
|
+
|
12
|
+
tree_3:
|
13
|
+
id: 1003
|
14
|
+
type: TreeMixin
|
15
|
+
parent_id: 1002
|
16
|
+
|
17
|
+
tree_4:
|
18
|
+
id: 1004
|
19
|
+
type: TreeMixin
|
20
|
+
parent_id: 1001
|
21
|
+
|
22
|
+
tree2_1:
|
23
|
+
id: 1005
|
24
|
+
type: TreeMixin
|
25
|
+
parent_id:
|
26
|
+
|
27
|
+
tree3_1:
|
28
|
+
id: 1006
|
29
|
+
type: TreeMixin
|
30
|
+
parent_id:
|
31
|
+
|
32
|
+
tree_without_order_1:
|
33
|
+
id: 1101
|
34
|
+
type: TreeMixinWithoutOrder
|
35
|
+
parent_id:
|
36
|
+
|
37
|
+
tree_without_order_2:
|
38
|
+
id: 1100
|
39
|
+
type: TreeMixinWithoutOrder
|
40
|
+
parent_id:
|
41
|
+
|
42
|
+
recursively_cascaded_tree_1:
|
43
|
+
id: 5005
|
44
|
+
type: RecursivelyCascadedTreeMixin
|
45
|
+
parent_id:
|
46
|
+
|
47
|
+
recursively_cascaded_tree_2:
|
48
|
+
id: 5006
|
49
|
+
type: RecursivelyCascadedTreeMixin
|
50
|
+
parent_id: 5005
|
51
|
+
|
52
|
+
recursively_cascaded_tree_3:
|
53
|
+
id: 5007
|
54
|
+
type: RecursivelyCascadedTreeMixin
|
55
|
+
parent_id: 5006
|
56
|
+
|
57
|
+
recursively_cascaded_tree_4:
|
58
|
+
id: 5008
|
59
|
+
type: RecursivelyCascadedTreeMixin
|
60
|
+
parent_id: 5007
|
61
|
+
|
62
|
+
# List mixins
|
63
|
+
|
64
|
+
<% (1..4).each do |counter| %>
|
65
|
+
list_<%= counter %>:
|
66
|
+
id: <%= counter+1006 %>
|
67
|
+
pos: <%= counter %>
|
68
|
+
type: ListMixin
|
69
|
+
parent_id: 5
|
70
|
+
<% end %>
|
71
|
+
|
72
|
+
# Nested set mixins
|
73
|
+
|
74
|
+
<% (1..10).each do |counter| %>
|
75
|
+
set_<%= counter %>:
|
76
|
+
id: <%= counter+3000 %>
|
77
|
+
type: NestedSet
|
78
|
+
<% end %>
|
79
|
+
|
80
|
+
# Nested set with STI
|
81
|
+
<%
|
82
|
+
[ [3100, 0, 1, 10, "NestedSetSuperclass"],
|
83
|
+
[3101, 3100, 2, 5, "NestedSetSubclass"],
|
84
|
+
[3102, 3101, 3, 4, "NestedSetSuperclass"],
|
85
|
+
[3103, 3100, 6, 9, "NestedSetSuperclass"],
|
86
|
+
[3104, 3103, 7, 8, "NestedSetSubclass"]
|
87
|
+
].each do |sti| %>
|
88
|
+
sti_set_<%= sti[0] %>:
|
89
|
+
id: <%= sti[0] %>
|
90
|
+
parent_id: <%= sti[1] %>
|
91
|
+
lft: <%= sti[2] %>
|
92
|
+
rgt: <%= sti[3] %>
|
93
|
+
type: <%= sti[4] %>
|
94
|
+
root_id: 3100
|
95
|
+
|
96
|
+
<% end %>
|
97
|
+
|
98
|
+
# Big old set
|
99
|
+
<%
|
100
|
+
[[4001, 0, 1, 20],
|
101
|
+
[4002, 4001, 2, 7],
|
102
|
+
[4003, 4002, 3, 4],
|
103
|
+
[4004, 4002, 5, 6],
|
104
|
+
[4005, 4001, 8, 13],
|
105
|
+
[4006, 4005, 9, 10],
|
106
|
+
[4007, 4005, 11, 12],
|
107
|
+
[4008, 4001, 14, 19],
|
108
|
+
[4009, 4008, 15, 16],
|
109
|
+
[4010, 4008, 17, 18]].each do |set| %>
|
110
|
+
tree_<%= set[0] %>:
|
111
|
+
id: <%= set[0]%>
|
112
|
+
parent_id: <%= set[1]%>
|
113
|
+
type: NestedSetWithStringScope
|
114
|
+
lft: <%= set[2]%>
|
115
|
+
rgt: <%= set[3]%>
|
116
|
+
root_id: 42
|
117
|
+
|
118
|
+
<% end %>
|
119
|
+
|
120
|
+
# subclasses of list items
|
121
|
+
<% (1..4).each do |i| %>
|
122
|
+
list_sub_<%= i %>:
|
123
|
+
id: <%= i + 5000 %>
|
124
|
+
pos: <%= i %>
|
125
|
+
parent_id: 5000
|
126
|
+
type: <%= (i % 2 == 1) ? ListMixinSub1 : ListMixinSub2 %>
|
127
|
+
<% end %>
|