activerecord_authorails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. data/CHANGELOG +3043 -0
  2. data/README +360 -0
  3. data/RUNNING_UNIT_TESTS +64 -0
  4. data/Rakefile +226 -0
  5. data/examples/associations.png +0 -0
  6. data/examples/associations.rb +87 -0
  7. data/examples/shared_setup.rb +15 -0
  8. data/examples/validation.rb +85 -0
  9. data/install.rb +30 -0
  10. data/lib/active_record.rb +85 -0
  11. data/lib/active_record/acts/list.rb +244 -0
  12. data/lib/active_record/acts/nested_set.rb +211 -0
  13. data/lib/active_record/acts/tree.rb +89 -0
  14. data/lib/active_record/aggregations.rb +191 -0
  15. data/lib/active_record/associations.rb +1637 -0
  16. data/lib/active_record/associations/association_collection.rb +190 -0
  17. data/lib/active_record/associations/association_proxy.rb +158 -0
  18. data/lib/active_record/associations/belongs_to_association.rb +56 -0
  19. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +50 -0
  20. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +169 -0
  21. data/lib/active_record/associations/has_many_association.rb +210 -0
  22. data/lib/active_record/associations/has_many_through_association.rb +247 -0
  23. data/lib/active_record/associations/has_one_association.rb +80 -0
  24. data/lib/active_record/attribute_methods.rb +75 -0
  25. data/lib/active_record/base.rb +2164 -0
  26. data/lib/active_record/calculations.rb +270 -0
  27. data/lib/active_record/callbacks.rb +367 -0
  28. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +279 -0
  29. data/lib/active_record/connection_adapters/abstract/database_statements.rb +130 -0
  30. data/lib/active_record/connection_adapters/abstract/quoting.rb +58 -0
  31. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +343 -0
  32. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +310 -0
  33. data/lib/active_record/connection_adapters/abstract_adapter.rb +161 -0
  34. data/lib/active_record/connection_adapters/db2_adapter.rb +228 -0
  35. data/lib/active_record/connection_adapters/firebird_adapter.rb +728 -0
  36. data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
  37. data/lib/active_record/connection_adapters/mysql_adapter.rb +414 -0
  38. data/lib/active_record/connection_adapters/openbase_adapter.rb +350 -0
  39. data/lib/active_record/connection_adapters/oracle_adapter.rb +689 -0
  40. data/lib/active_record/connection_adapters/postgresql_adapter.rb +584 -0
  41. data/lib/active_record/connection_adapters/sqlite_adapter.rb +407 -0
  42. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +591 -0
  43. data/lib/active_record/connection_adapters/sybase_adapter.rb +662 -0
  44. data/lib/active_record/deprecated_associations.rb +104 -0
  45. data/lib/active_record/deprecated_finders.rb +44 -0
  46. data/lib/active_record/fixtures.rb +628 -0
  47. data/lib/active_record/locking/optimistic.rb +106 -0
  48. data/lib/active_record/locking/pessimistic.rb +77 -0
  49. data/lib/active_record/migration.rb +394 -0
  50. data/lib/active_record/observer.rb +178 -0
  51. data/lib/active_record/query_cache.rb +64 -0
  52. data/lib/active_record/reflection.rb +222 -0
  53. data/lib/active_record/schema.rb +58 -0
  54. data/lib/active_record/schema_dumper.rb +149 -0
  55. data/lib/active_record/timestamp.rb +51 -0
  56. data/lib/active_record/transactions.rb +136 -0
  57. data/lib/active_record/validations.rb +843 -0
  58. data/lib/active_record/vendor/db2.rb +362 -0
  59. data/lib/active_record/vendor/mysql.rb +1214 -0
  60. data/lib/active_record/vendor/simple.rb +693 -0
  61. data/lib/active_record/version.rb +9 -0
  62. data/lib/active_record/wrappers/yaml_wrapper.rb +15 -0
  63. data/lib/active_record/wrappings.rb +58 -0
  64. data/lib/active_record/xml_serialization.rb +308 -0
  65. data/test/aaa_create_tables_test.rb +59 -0
  66. data/test/abstract_unit.rb +77 -0
  67. data/test/active_schema_test_mysql.rb +31 -0
  68. data/test/adapter_test.rb +87 -0
  69. data/test/adapter_test_sqlserver.rb +81 -0
  70. data/test/aggregations_test.rb +95 -0
  71. data/test/all.sh +8 -0
  72. data/test/ar_schema_test.rb +33 -0
  73. data/test/association_inheritance_reload.rb +14 -0
  74. data/test/associations/callbacks_test.rb +126 -0
  75. data/test/associations/cascaded_eager_loading_test.rb +138 -0
  76. data/test/associations/eager_test.rb +393 -0
  77. data/test/associations/extension_test.rb +42 -0
  78. data/test/associations/join_model_test.rb +497 -0
  79. data/test/associations_test.rb +1809 -0
  80. data/test/attribute_methods_test.rb +49 -0
  81. data/test/base_test.rb +1586 -0
  82. data/test/binary_test.rb +37 -0
  83. data/test/calculations_test.rb +219 -0
  84. data/test/callbacks_test.rb +377 -0
  85. data/test/class_inheritable_attributes_test.rb +32 -0
  86. data/test/column_alias_test.rb +17 -0
  87. data/test/connection_test_firebird.rb +8 -0
  88. data/test/connections/native_db2/connection.rb +25 -0
  89. data/test/connections/native_firebird/connection.rb +26 -0
  90. data/test/connections/native_frontbase/connection.rb +27 -0
  91. data/test/connections/native_mysql/connection.rb +24 -0
  92. data/test/connections/native_openbase/connection.rb +21 -0
  93. data/test/connections/native_oracle/connection.rb +27 -0
  94. data/test/connections/native_postgresql/connection.rb +23 -0
  95. data/test/connections/native_sqlite/connection.rb +34 -0
  96. data/test/connections/native_sqlite3/connection.rb +34 -0
  97. data/test/connections/native_sqlite3/in_memory_connection.rb +18 -0
  98. data/test/connections/native_sqlserver/connection.rb +23 -0
  99. data/test/connections/native_sqlserver_odbc/connection.rb +25 -0
  100. data/test/connections/native_sybase/connection.rb +23 -0
  101. data/test/copy_table_sqlite.rb +64 -0
  102. data/test/datatype_test_postgresql.rb +52 -0
  103. data/test/default_test_firebird.rb +16 -0
  104. data/test/defaults_test.rb +60 -0
  105. data/test/deprecated_associations_test.rb +396 -0
  106. data/test/deprecated_finder_test.rb +151 -0
  107. data/test/empty_date_time_test.rb +25 -0
  108. data/test/finder_test.rb +504 -0
  109. data/test/fixtures/accounts.yml +28 -0
  110. data/test/fixtures/author.rb +99 -0
  111. data/test/fixtures/author_favorites.yml +4 -0
  112. data/test/fixtures/authors.yml +7 -0
  113. data/test/fixtures/auto_id.rb +4 -0
  114. data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +1 -0
  115. data/test/fixtures/bad_fixtures/attr_with_spaces +1 -0
  116. data/test/fixtures/bad_fixtures/blank_line +3 -0
  117. data/test/fixtures/bad_fixtures/duplicate_attributes +3 -0
  118. data/test/fixtures/bad_fixtures/missing_value +1 -0
  119. data/test/fixtures/binary.rb +2 -0
  120. data/test/fixtures/categories.yml +14 -0
  121. data/test/fixtures/categories/special_categories.yml +9 -0
  122. data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
  123. data/test/fixtures/categories_ordered.yml +7 -0
  124. data/test/fixtures/categories_posts.yml +23 -0
  125. data/test/fixtures/categorization.rb +5 -0
  126. data/test/fixtures/categorizations.yml +17 -0
  127. data/test/fixtures/category.rb +20 -0
  128. data/test/fixtures/column_name.rb +3 -0
  129. data/test/fixtures/comment.rb +23 -0
  130. data/test/fixtures/comments.yml +59 -0
  131. data/test/fixtures/companies.yml +55 -0
  132. data/test/fixtures/company.rb +107 -0
  133. data/test/fixtures/company_in_module.rb +59 -0
  134. data/test/fixtures/computer.rb +3 -0
  135. data/test/fixtures/computers.yml +4 -0
  136. data/test/fixtures/course.rb +3 -0
  137. data/test/fixtures/courses.yml +7 -0
  138. data/test/fixtures/customer.rb +55 -0
  139. data/test/fixtures/customers.yml +17 -0
  140. data/test/fixtures/db_definitions/db2.drop.sql +32 -0
  141. data/test/fixtures/db_definitions/db2.sql +231 -0
  142. data/test/fixtures/db_definitions/db22.drop.sql +2 -0
  143. data/test/fixtures/db_definitions/db22.sql +5 -0
  144. data/test/fixtures/db_definitions/firebird.drop.sql +63 -0
  145. data/test/fixtures/db_definitions/firebird.sql +304 -0
  146. data/test/fixtures/db_definitions/firebird2.drop.sql +2 -0
  147. data/test/fixtures/db_definitions/firebird2.sql +6 -0
  148. data/test/fixtures/db_definitions/frontbase.drop.sql +32 -0
  149. data/test/fixtures/db_definitions/frontbase.sql +268 -0
  150. data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
  151. data/test/fixtures/db_definitions/frontbase2.sql +4 -0
  152. data/test/fixtures/db_definitions/mysql.drop.sql +32 -0
  153. data/test/fixtures/db_definitions/mysql.sql +234 -0
  154. data/test/fixtures/db_definitions/mysql2.drop.sql +2 -0
  155. data/test/fixtures/db_definitions/mysql2.sql +5 -0
  156. data/test/fixtures/db_definitions/openbase.drop.sql +2 -0
  157. data/test/fixtures/db_definitions/openbase.sql +302 -0
  158. data/test/fixtures/db_definitions/openbase2.drop.sql +2 -0
  159. data/test/fixtures/db_definitions/openbase2.sql +7 -0
  160. data/test/fixtures/db_definitions/oracle.drop.sql +65 -0
  161. data/test/fixtures/db_definitions/oracle.sql +325 -0
  162. data/test/fixtures/db_definitions/oracle2.drop.sql +2 -0
  163. data/test/fixtures/db_definitions/oracle2.sql +6 -0
  164. data/test/fixtures/db_definitions/postgresql.drop.sql +37 -0
  165. data/test/fixtures/db_definitions/postgresql.sql +263 -0
  166. data/test/fixtures/db_definitions/postgresql2.drop.sql +2 -0
  167. data/test/fixtures/db_definitions/postgresql2.sql +5 -0
  168. data/test/fixtures/db_definitions/schema.rb +60 -0
  169. data/test/fixtures/db_definitions/sqlite.drop.sql +32 -0
  170. data/test/fixtures/db_definitions/sqlite.sql +215 -0
  171. data/test/fixtures/db_definitions/sqlite2.drop.sql +2 -0
  172. data/test/fixtures/db_definitions/sqlite2.sql +5 -0
  173. data/test/fixtures/db_definitions/sqlserver.drop.sql +34 -0
  174. data/test/fixtures/db_definitions/sqlserver.sql +243 -0
  175. data/test/fixtures/db_definitions/sqlserver2.drop.sql +2 -0
  176. data/test/fixtures/db_definitions/sqlserver2.sql +5 -0
  177. data/test/fixtures/db_definitions/sybase.drop.sql +34 -0
  178. data/test/fixtures/db_definitions/sybase.sql +218 -0
  179. data/test/fixtures/db_definitions/sybase2.drop.sql +4 -0
  180. data/test/fixtures/db_definitions/sybase2.sql +5 -0
  181. data/test/fixtures/default.rb +2 -0
  182. data/test/fixtures/developer.rb +52 -0
  183. data/test/fixtures/developers.yml +21 -0
  184. data/test/fixtures/developers_projects.yml +17 -0
  185. data/test/fixtures/developers_projects/david_action_controller +3 -0
  186. data/test/fixtures/developers_projects/david_active_record +3 -0
  187. data/test/fixtures/developers_projects/jamis_active_record +2 -0
  188. data/test/fixtures/edge.rb +5 -0
  189. data/test/fixtures/edges.yml +6 -0
  190. data/test/fixtures/entrant.rb +3 -0
  191. data/test/fixtures/entrants.yml +14 -0
  192. data/test/fixtures/fk_test_has_fk.yml +3 -0
  193. data/test/fixtures/fk_test_has_pk.yml +2 -0
  194. data/test/fixtures/flowers.jpg +0 -0
  195. data/test/fixtures/funny_jokes.yml +10 -0
  196. data/test/fixtures/joke.rb +6 -0
  197. data/test/fixtures/keyboard.rb +3 -0
  198. data/test/fixtures/legacy_thing.rb +3 -0
  199. data/test/fixtures/legacy_things.yml +3 -0
  200. data/test/fixtures/migrations/1_people_have_last_names.rb +9 -0
  201. data/test/fixtures/migrations/2_we_need_reminders.rb +12 -0
  202. data/test/fixtures/migrations/3_innocent_jointable.rb +12 -0
  203. data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
  204. data/test/fixtures/migrations_with_duplicate/1_people_have_last_names.rb +9 -0
  205. data/test/fixtures/migrations_with_duplicate/2_we_need_reminders.rb +12 -0
  206. data/test/fixtures/migrations_with_duplicate/3_foo.rb +7 -0
  207. data/test/fixtures/migrations_with_duplicate/3_innocent_jointable.rb +12 -0
  208. data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
  209. data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
  210. data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
  211. data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
  212. data/test/fixtures/mixed_case_monkey.rb +3 -0
  213. data/test/fixtures/mixed_case_monkeys.yml +6 -0
  214. data/test/fixtures/mixin.rb +63 -0
  215. data/test/fixtures/mixins.yml +127 -0
  216. data/test/fixtures/movie.rb +5 -0
  217. data/test/fixtures/movies.yml +7 -0
  218. data/test/fixtures/naked/csv/accounts.csv +1 -0
  219. data/test/fixtures/naked/yml/accounts.yml +1 -0
  220. data/test/fixtures/naked/yml/companies.yml +1 -0
  221. data/test/fixtures/naked/yml/courses.yml +1 -0
  222. data/test/fixtures/order.rb +4 -0
  223. data/test/fixtures/people.yml +3 -0
  224. data/test/fixtures/person.rb +4 -0
  225. data/test/fixtures/post.rb +58 -0
  226. data/test/fixtures/posts.yml +48 -0
  227. data/test/fixtures/project.rb +27 -0
  228. data/test/fixtures/projects.yml +7 -0
  229. data/test/fixtures/reader.rb +4 -0
  230. data/test/fixtures/readers.yml +4 -0
  231. data/test/fixtures/reply.rb +37 -0
  232. data/test/fixtures/subject.rb +4 -0
  233. data/test/fixtures/subscriber.rb +6 -0
  234. data/test/fixtures/subscribers/first +2 -0
  235. data/test/fixtures/subscribers/second +2 -0
  236. data/test/fixtures/tag.rb +7 -0
  237. data/test/fixtures/tagging.rb +6 -0
  238. data/test/fixtures/taggings.yml +18 -0
  239. data/test/fixtures/tags.yml +7 -0
  240. data/test/fixtures/task.rb +3 -0
  241. data/test/fixtures/tasks.yml +7 -0
  242. data/test/fixtures/topic.rb +25 -0
  243. data/test/fixtures/topics.yml +22 -0
  244. data/test/fixtures/vertex.rb +9 -0
  245. data/test/fixtures/vertices.yml +4 -0
  246. data/test/fixtures_test.rb +401 -0
  247. data/test/inheritance_test.rb +205 -0
  248. data/test/lifecycle_test.rb +137 -0
  249. data/test/locking_test.rb +190 -0
  250. data/test/method_scoping_test.rb +416 -0
  251. data/test/migration_test.rb +768 -0
  252. data/test/migration_test_firebird.rb +124 -0
  253. data/test/mixin_nested_set_test.rb +196 -0
  254. data/test/mixin_test.rb +550 -0
  255. data/test/modules_test.rb +34 -0
  256. data/test/multiple_db_test.rb +60 -0
  257. data/test/pk_test.rb +104 -0
  258. data/test/readonly_test.rb +107 -0
  259. data/test/reflection_test.rb +159 -0
  260. data/test/schema_authorization_test_postgresql.rb +75 -0
  261. data/test/schema_dumper_test.rb +96 -0
  262. data/test/schema_test_postgresql.rb +64 -0
  263. data/test/synonym_test_oracle.rb +17 -0
  264. data/test/table_name_test_sqlserver.rb +23 -0
  265. data/test/threaded_connections_test.rb +48 -0
  266. data/test/transactions_test.rb +230 -0
  267. data/test/unconnected_test.rb +32 -0
  268. data/test/validations_test.rb +1097 -0
  269. data/test/xml_serialization_test.rb +125 -0
  270. metadata +365 -0
@@ -0,0 +1,5 @@
1
+ class Movie < ActiveRecord::Base
2
+ def self.primary_key
3
+ "movieid"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ first:
2
+ movieid: 1
3
+ name: Terminator
4
+
5
+ second:
6
+ movieid: 2
7
+ name: Gladiator
@@ -0,0 +1 @@
1
+ # i wonder what will happen here
@@ -0,0 +1 @@
1
+ qwerty
@@ -0,0 +1,4 @@
1
+ class Order < ActiveRecord::Base
2
+ belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
3
+ belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
4
+ end
@@ -0,0 +1,3 @@
1
+ michael:
2
+ id: 1
3
+ first_name: Michael
@@ -0,0 +1,4 @@
1
+ class Person < ActiveRecord::Base
2
+ has_many :readers
3
+ has_many :posts, :through => :readers
4
+ end
@@ -0,0 +1,58 @@
1
+ class Post < ActiveRecord::Base
2
+ belongs_to :author do
3
+ def greeting
4
+ "hello"
5
+ end
6
+ end
7
+
8
+ belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
9
+
10
+ has_many :comments, :order => "body" do
11
+ def find_most_recent
12
+ find(:first, :order => "id DESC")
13
+ end
14
+ end
15
+
16
+ has_one :very_special_comment
17
+ has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
18
+ has_many :special_comments
19
+
20
+ has_and_belongs_to_many :categories
21
+ has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
22
+
23
+ has_many :taggings, :as => :taggable
24
+ has_many :tags, :through => :taggings, :include => :tagging do
25
+ def add_joins_and_select
26
+ find :all, :select => 'tags.*, authors.id as author_id', :include => false,
27
+ :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
28
+ end
29
+ end
30
+
31
+ has_many :funky_tags, :through => :taggings, :source => :tag
32
+ has_many :super_tags, :through => :taggings
33
+ has_one :tagging, :as => :taggable
34
+
35
+ has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
36
+ has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
37
+
38
+ has_many :categorizations, :foreign_key => :category_id
39
+ has_many :authors, :through => :categorizations
40
+
41
+ has_many :readers
42
+ has_many :people, :through => :readers
43
+
44
+ def self.what_are_you
45
+ 'a post...'
46
+ end
47
+ end
48
+
49
+ class SpecialPost < Post; end
50
+
51
+ class StiPost < Post
52
+ self.abstract_class = true
53
+ has_one :special_comment, :class_name => "SpecialComment"
54
+ end
55
+
56
+ class SubStiPost < StiPost
57
+ self.table_name = Post.table_name
58
+ end
@@ -0,0 +1,48 @@
1
+ welcome:
2
+ id: 1
3
+ author_id: 1
4
+ title: Welcome to the weblog
5
+ body: Such a lovely day
6
+ type: Post
7
+
8
+ thinking:
9
+ id: 2
10
+ author_id: 1
11
+ title: So I was thinking
12
+ body: Like I hopefully always am
13
+ type: SpecialPost
14
+
15
+ authorless:
16
+ id: 3
17
+ author_id: 0
18
+ title: I don't have any comments
19
+ body: I just don't want to
20
+ type: Post
21
+
22
+ sti_comments:
23
+ id: 4
24
+ author_id: 1
25
+ title: sti comments
26
+ body: hello
27
+ type: Post
28
+
29
+ sti_post_and_comments:
30
+ id: 5
31
+ author_id: 1
32
+ title: sti me
33
+ body: hello
34
+ type: StiPost
35
+
36
+ sti_habtm:
37
+ id: 6
38
+ author_id: 1
39
+ title: habtm sti test
40
+ body: hello
41
+ type: Post
42
+
43
+ eager_other:
44
+ id: 7
45
+ author_id: 2
46
+ title: eager loading with OR'd conditions
47
+ body: hello
48
+ type: Post
@@ -0,0 +1,27 @@
1
+ class Project < ActiveRecord::Base
2
+ has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc'
3
+ has_and_belongs_to_many :non_unique_developers, :order => 'developers.name desc, developers.id desc', :class_name => 'Developer'
4
+ has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1
5
+ has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true
6
+ has_and_belongs_to_many :developers_named_david_with_hash_conditions, :class_name => "Developer", :conditions => { :name => 'David' }, :uniq => true
7
+ has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
8
+ has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id}'
9
+ has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}"
10
+ has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id}"},
11
+ :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id}"},
12
+ :before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
13
+ :after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
14
+
15
+ attr_accessor :developers_log
16
+
17
+ def after_initialize
18
+ @developers_log = []
19
+ end
20
+
21
+ end
22
+
23
+ class SpecialProject < Project
24
+ def hello_world
25
+ "hello there!"
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ action_controller:
2
+ id: 2
3
+ name: Active Controller
4
+
5
+ active_record:
6
+ id: 1
7
+ name: Active Record
@@ -0,0 +1,4 @@
1
+ class Reader < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :person
4
+ end
@@ -0,0 +1,4 @@
1
+ michael_welcome:
2
+ id: 1
3
+ post_id: 1
4
+ person_id: 1
@@ -0,0 +1,37 @@
1
+ require 'fixtures/topic'
2
+
3
+ class Reply < Topic
4
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
5
+ has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
6
+
7
+ validate :errors_on_empty_content
8
+ validate_on_create :title_is_wrong_create
9
+
10
+ attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
11
+
12
+ def validate
13
+ errors.add("title", "Empty") unless attribute_present? "title"
14
+ end
15
+
16
+ def errors_on_empty_content
17
+ errors.add("content", "Empty") unless attribute_present? "content"
18
+ end
19
+
20
+ def validate_on_create
21
+ if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
22
+ errors.add("title", "is Content Mismatch")
23
+ end
24
+ end
25
+
26
+ def title_is_wrong_create
27
+ errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
28
+ end
29
+
30
+ def validate_on_update
31
+ errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
32
+ end
33
+ end
34
+
35
+ class SillyReply < Reply
36
+ belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
37
+ end
@@ -0,0 +1,4 @@
1
+ # used for OracleSynonymTest, see test/synonym_test_oci.rb
2
+ #
3
+ class Subject < ActiveRecord::Base
4
+ end
@@ -0,0 +1,6 @@
1
+ class Subscriber < ActiveRecord::Base
2
+ set_primary_key 'nick'
3
+ end
4
+
5
+ class SpecialSubscriber < Subscriber
6
+ end
@@ -0,0 +1,2 @@
1
+ nick => alterself
2
+ name => Luke Holden
@@ -0,0 +1,2 @@
1
+ nick => webster132
2
+ name => David Heinemeier Hansson
@@ -0,0 +1,7 @@
1
+ class Tag < ActiveRecord::Base
2
+ has_many :taggings
3
+ has_many :taggables, :through => :taggings
4
+ has_one :tagging
5
+
6
+ has_many :tagged_posts, :through => :taggings, :source => :taggable, :source_type => 'Post'
7
+ end
@@ -0,0 +1,6 @@
1
+ class Tagging < ActiveRecord::Base
2
+ belongs_to :tag, :include => :tagging
3
+ belongs_to :super_tag, :class_name => 'Tag', :foreign_key => 'super_tag_id'
4
+ belongs_to :invalid_tag, :class_name => 'Tag', :foreign_key => 'tag_id'
5
+ belongs_to :taggable, :polymorphic => true, :counter_cache => true
6
+ end
@@ -0,0 +1,18 @@
1
+ welcome_general:
2
+ id: 1
3
+ tag_id: 1
4
+ super_tag_id: 2
5
+ taggable_id: 1
6
+ taggable_type: Post
7
+
8
+ thinking_general:
9
+ id: 2
10
+ tag_id: 1
11
+ taggable_id: 2
12
+ taggable_type: Post
13
+
14
+ fake:
15
+ id: 3
16
+ tag_id: 1
17
+ taggable_id: 1
18
+ taggable_type: FakeModel
@@ -0,0 +1,7 @@
1
+ general:
2
+ id: 1
3
+ name: General
4
+
5
+ misc:
6
+ id: 2
7
+ name: Misc
@@ -0,0 +1,3 @@
1
+ class Task < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ first_task:
3
+ id: 1
4
+ starting: 2005-03-30t06:30:00.00+01:00
5
+ ending: 2005-03-30t08:30:00.00+01:00
6
+ another_task:
7
+ id: 2
@@ -0,0 +1,25 @@
1
+ class Topic < ActiveRecord::Base
2
+ has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
3
+ serialize :content
4
+
5
+ before_create :default_written_on
6
+ before_destroy :destroy_children
7
+
8
+ def parent
9
+ Topic.find(parent_id)
10
+ end
11
+
12
+ # trivial method for testing Array#to_xml with :methods
13
+ def topic_id
14
+ id
15
+ end
16
+
17
+ protected
18
+ def default_written_on
19
+ self.written_on = Time.now unless attribute_present?("written_on")
20
+ end
21
+
22
+ def destroy_children
23
+ self.class.delete_all "parent_id = #{id}"
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ first:
2
+ id: 1
3
+ title: The First Topic
4
+ author_name: David
5
+ author_email_address: david@loudthinking.com
6
+ written_on: 2003-07-16t15:28:11.2233+01:00
7
+ last_read: 2004-04-15
8
+ bonus_time: 2005-01-30t15:28:00.00+01:00
9
+ content: Have a nice day
10
+ approved: false
11
+ replies_count: 1
12
+
13
+ second:
14
+ id: 2
15
+ title: The Second Topic's of the day
16
+ author_name: Mary
17
+ written_on: 2003-07-15t15:28:00.0099+01:00
18
+ content: Have a nice day
19
+ approved: true
20
+ replies_count: 0
21
+ parent_id: 1
22
+ type: Reply
@@ -0,0 +1,9 @@
1
+ # This class models a vertex in a directed graph.
2
+ class Vertex < ActiveRecord::Base
3
+ has_many :sink_edges, :class_name => 'Edge', :foreign_key => 'source_id'
4
+ has_many :sinks, :through => :sink_edges
5
+
6
+ has_and_belongs_to_many :sources,
7
+ :class_name => 'Vertex', :join_table => 'edges',
8
+ :foreign_key => 'sink_id', :association_foreign_key => 'source_id'
9
+ end
@@ -0,0 +1,4 @@
1
+ <% (1..5).each do |id| %>
2
+ vertex_<%= id %>:
3
+ id: <%= id %>
4
+ <% end %>
@@ -0,0 +1,401 @@
1
+ require 'abstract_unit'
2
+ require 'fixtures/topic'
3
+ require 'fixtures/developer'
4
+ require 'fixtures/company'
5
+ require 'fixtures/task'
6
+ require 'fixtures/reply'
7
+ require 'fixtures/joke'
8
+ require 'fixtures/course'
9
+ require 'fixtures/category'
10
+
11
+ class FixturesTest < Test::Unit::TestCase
12
+ self.use_instantiated_fixtures = true
13
+ self.use_transactional_fixtures = false
14
+
15
+ fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes
16
+
17
+ FIXTURES = %w( accounts companies customers
18
+ developers developers_projects entrants
19
+ movies projects subscribers topics tasks )
20
+ MATCH_ATTRIBUTE_NAME = /[a-zA-Z][-_\w]*/
21
+
22
+ def test_clean_fixtures
23
+ FIXTURES.each do |name|
24
+ fixtures = nil
25
+ assert_nothing_raised { fixtures = create_fixtures(name) }
26
+ assert_kind_of(Fixtures, fixtures)
27
+ fixtures.each { |name, fixture|
28
+ fixture.each { |key, value|
29
+ assert_match(MATCH_ATTRIBUTE_NAME, key)
30
+ }
31
+ }
32
+ end
33
+ end
34
+
35
+ def test_multiple_clean_fixtures
36
+ fixtures_array = nil
37
+ assert_nothing_raised { fixtures_array = create_fixtures(*FIXTURES) }
38
+ assert_kind_of(Array, fixtures_array)
39
+ fixtures_array.each { |fixtures| assert_kind_of(Fixtures, fixtures) }
40
+ end
41
+
42
+ def test_attributes
43
+ topics = create_fixtures("topics")
44
+ assert_equal("The First Topic", topics["first"]["title"])
45
+ assert_nil(topics["second"]["author_email_address"])
46
+ end
47
+
48
+ def test_inserts
49
+ topics = create_fixtures("topics")
50
+ firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
51
+ assert_equal("The First Topic", firstRow["title"])
52
+
53
+ secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
54
+ assert_nil(secondRow["author_email_address"])
55
+ end
56
+
57
+ if ActiveRecord::Base.connection.supports_migrations?
58
+ def test_inserts_with_pre_and_suffix
59
+ ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t|
60
+ t.column :title, :string
61
+ t.column :author_name, :string
62
+ t.column :author_email_address, :string
63
+ t.column :written_on, :datetime
64
+ t.column :bonus_time, :time
65
+ t.column :last_read, :date
66
+ t.column :content, :string
67
+ t.column :approved, :boolean, :default => true
68
+ t.column :replies_count, :integer, :default => 0
69
+ t.column :parent_id, :integer
70
+ t.column :type, :string, :limit => 50
71
+ end
72
+
73
+ # Store existing prefix/suffix
74
+ old_prefix = ActiveRecord::Base.table_name_prefix
75
+ old_suffix = ActiveRecord::Base.table_name_suffix
76
+
77
+ # Set a prefix/suffix we can test against
78
+ ActiveRecord::Base.table_name_prefix = 'prefix_'
79
+ ActiveRecord::Base.table_name_suffix = '_suffix'
80
+
81
+ topics = create_fixtures("topics")
82
+
83
+ firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'")
84
+ assert_equal("The First Topic", firstRow["title"])
85
+
86
+ secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
87
+ assert_nil(secondRow["author_email_address"])
88
+ ensure
89
+ # Restore prefix/suffix to its previous values
90
+ ActiveRecord::Base.table_name_prefix = old_prefix
91
+ ActiveRecord::Base.table_name_suffix = old_suffix
92
+
93
+ ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil
94
+ end
95
+ end
96
+
97
+ def test_insert_with_datetime
98
+ topics = create_fixtures("tasks")
99
+ first = Task.find(1)
100
+ assert first
101
+ end
102
+
103
+
104
+ def test_bad_format
105
+ path = File.join(File.dirname(__FILE__), 'fixtures', 'bad_fixtures')
106
+ Dir.entries(path).each do |file|
107
+ next unless File.file?(file) and file !~ Fixtures::DEFAULT_FILTER_RE
108
+ assert_raise(Fixture::FormatError) {
109
+ Fixture.new(bad_fixtures_path, file)
110
+ }
111
+ end
112
+ end
113
+
114
+ def test_deprecated_yaml_extension
115
+ assert_raise(Fixture::FormatError) {
116
+ Fixtures.new(nil, 'bad_extension', 'BadExtension', File.join(File.dirname(__FILE__), 'fixtures'))
117
+ }
118
+ end
119
+
120
+ def test_logger_level_invariant
121
+ level = ActiveRecord::Base.logger.level
122
+ create_fixtures('topics')
123
+ assert_equal level, ActiveRecord::Base.logger.level
124
+ end
125
+
126
+ def test_instantiation
127
+ topics = create_fixtures("topics")
128
+ assert_kind_of Topic, topics["first"].find
129
+ end
130
+
131
+ def test_complete_instantiation
132
+ assert_equal 2, @topics.size
133
+ assert_equal "The First Topic", @first.title
134
+ end
135
+
136
+ def test_fixtures_from_root_yml_with_instantiation
137
+ # assert_equal 2, @accounts.size
138
+ assert_equal 50, @unknown.credit_limit
139
+ end
140
+
141
+ def test_erb_in_fixtures
142
+ assert_equal 11, @developers.size
143
+ assert_equal "fixture_5", @dev_5.name
144
+ end
145
+
146
+ def test_empty_yaml_fixture
147
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', File.dirname(__FILE__) + "/fixtures/naked/yml/accounts")
148
+ end
149
+
150
+ def test_empty_yaml_fixture_with_a_comment_in_it
151
+ assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', File.dirname(__FILE__) + "/fixtures/naked/yml/companies")
152
+ end
153
+
154
+ def test_dirty_dirty_yaml_file
155
+ assert_raises(Fixture::FormatError) do
156
+ Fixtures.new( Account.connection, "courses", 'Course', File.dirname(__FILE__) + "/fixtures/naked/yml/courses")
157
+ end
158
+ end
159
+
160
+ def test_empty_csv_fixtures
161
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', File.dirname(__FILE__) + "/fixtures/naked/csv/accounts")
162
+ end
163
+
164
+ def test_omap_fixtures
165
+ assert_nothing_raised do
166
+ fixtures = Fixtures.new(Account.connection, 'categories', 'Category', File.dirname(__FILE__) + '/fixtures/categories_ordered')
167
+
168
+ i = 0
169
+ fixtures.each do |name, fixture|
170
+ assert_equal "fixture_no_#{i}", name
171
+ assert_equal "Category #{i}", fixture['name']
172
+ i += 1
173
+ end
174
+ end
175
+ end
176
+
177
+
178
+ def test_yml_file_in_subdirectory
179
+ assert_equal(categories(:sub_special_1).name, "A special category in a subdir file")
180
+ assert_equal(categories(:sub_special_1).class, SpecialCategory)
181
+ end
182
+
183
+ def test_subsubdir_file_with_arbitrary_name
184
+ assert_equal(categories(:sub_special_3).name, "A special category in an arbitrarily named subsubdir file")
185
+ assert_equal(categories(:sub_special_3).class, SpecialCategory)
186
+ end
187
+
188
+
189
+ end
190
+
191
+ if Account.connection.respond_to?(:reset_pk_sequence!)
192
+ class FixturesResetPkSequenceTest < Test::Unit::TestCase
193
+ fixtures :accounts
194
+ fixtures :companies
195
+
196
+ def setup
197
+ @instances = [Account.new(:credit_limit => 50), Company.new(:name => 'RoR Consulting')]
198
+ end
199
+
200
+ def test_resets_to_min_pk_with_specified_pk_and_sequence
201
+ @instances.each do |instance|
202
+ model = instance.class
203
+ model.delete_all
204
+ model.connection.reset_pk_sequence!(model.table_name, model.primary_key, model.sequence_name)
205
+
206
+ instance.save!
207
+ assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed."
208
+ end
209
+ end
210
+
211
+ def test_resets_to_min_pk_with_default_pk_and_sequence
212
+ @instances.each do |instance|
213
+ model = instance.class
214
+ model.delete_all
215
+ model.connection.reset_pk_sequence!(model.table_name)
216
+
217
+ instance.save!
218
+ assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed."
219
+ end
220
+ end
221
+
222
+ def test_create_fixtures_resets_sequences
223
+ @instances.each do |instance|
224
+ max_id = create_fixtures(instance.class.table_name).inject(0) do |max_id, (name, fixture)|
225
+ fixture_id = fixture['id'].to_i
226
+ fixture_id > max_id ? fixture_id : max_id
227
+ end
228
+
229
+ # Clone the last fixture to check that it gets the next greatest id.
230
+ instance.save!
231
+ assert_equal max_id + 1, instance.id, "Sequence reset for #{instance.class.table_name} failed."
232
+ end
233
+ end
234
+ end
235
+ end
236
+
237
+
238
+ class FixturesWithoutInstantiationTest < Test::Unit::TestCase
239
+ self.use_instantiated_fixtures = false
240
+ fixtures :topics, :developers, :accounts
241
+
242
+ def test_without_complete_instantiation
243
+ assert_nil @first
244
+ assert_nil @topics
245
+ assert_nil @developers
246
+ assert_nil @accounts
247
+ end
248
+
249
+ def test_fixtures_from_root_yml_without_instantiation
250
+ assert_nil @unknown
251
+ end
252
+
253
+ def test_accessor_methods
254
+ assert_equal "The First Topic", topics(:first).title
255
+ assert_equal "Jamis", developers(:jamis).name
256
+ assert_equal 50, accounts(:signals37).credit_limit
257
+ end
258
+ end
259
+
260
+
261
+ class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
262
+ self.use_instantiated_fixtures = true
263
+ self.use_instantiated_fixtures = :no_instances
264
+
265
+ fixtures :topics, :developers, :accounts
266
+
267
+ def test_without_instance_instantiation
268
+ assert_nil @first
269
+ assert_not_nil @topics
270
+ assert_not_nil @developers
271
+ assert_not_nil @accounts
272
+ end
273
+ end
274
+
275
+
276
+ class TransactionalFixturesTest < Test::Unit::TestCase
277
+ self.use_instantiated_fixtures = true
278
+ self.use_transactional_fixtures = true
279
+
280
+ fixtures :topics
281
+
282
+ def test_destroy
283
+ assert_not_nil @first
284
+ @first.destroy
285
+ end
286
+
287
+ def test_destroy_just_kidding
288
+ assert_not_nil @first
289
+ end
290
+ end
291
+
292
+
293
+ class MultipleFixturesTest < Test::Unit::TestCase
294
+ fixtures :topics
295
+ fixtures :developers, :accounts
296
+
297
+ def test_fixture_table_names
298
+ assert_equal %w(topics developers accounts), fixture_table_names
299
+ end
300
+ end
301
+
302
+
303
+ class OverlappingFixturesTest < Test::Unit::TestCase
304
+ fixtures :topics, :developers
305
+ fixtures :developers, :accounts
306
+
307
+ def test_fixture_table_names
308
+ assert_equal %w(topics developers accounts), fixture_table_names
309
+ end
310
+ end
311
+
312
+
313
+ class ForeignKeyFixturesTest < Test::Unit::TestCase
314
+ fixtures :fk_test_has_pk, :fk_test_has_fk
315
+
316
+ # if foreign keys are implemented and fixtures
317
+ # are not deleted in reverse order then this test
318
+ # case will raise StatementInvalid
319
+
320
+ def test_number1
321
+ assert true
322
+ end
323
+
324
+ def test_number2
325
+ assert true
326
+ end
327
+ end
328
+
329
+ class SetTableNameFixturesTest < Test::Unit::TestCase
330
+ set_fixture_class :funny_jokes => 'Joke'
331
+ fixtures :funny_jokes
332
+
333
+ def test_table_method
334
+ assert_kind_of Joke, funny_jokes(:a_joke)
335
+ end
336
+ end
337
+
338
+ class CustomConnectionFixturesTest < Test::Unit::TestCase
339
+ set_fixture_class :courses => Course
340
+ fixtures :courses
341
+
342
+ def test_connection
343
+ assert_kind_of Course, courses(:ruby)
344
+ assert_equal Course.connection, courses(:ruby).connection
345
+ end
346
+ end
347
+
348
+ class InvalidTableNameFixturesTest < Test::Unit::TestCase
349
+ fixtures :funny_jokes
350
+
351
+ def test_raises_error
352
+ assert_raises FixtureClassNotFound do
353
+ funny_jokes(:a_joke)
354
+ end
355
+ end
356
+ end
357
+
358
+ class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
359
+ set_fixture_class :funny_jokes => 'Joke'
360
+ fixtures :funny_jokes
361
+
362
+ def test_proper_escaped_fixture
363
+ assert_equal "The \\n Aristocrats\nAte the candy\n", funny_jokes(:another_joke).name
364
+ end
365
+ end
366
+
367
+ class DevelopersProject; end;
368
+
369
+ class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
370
+ fixtures :developers_projects
371
+
372
+ def test_this_should_run_cleanly
373
+ assert true
374
+ end
375
+ end
376
+
377
+
378
+ class FixturesBrokenRollbackTest < Test::Unit::TestCase
379
+ def blank_setup; end
380
+ alias_method :ar_setup_with_fixtures, :setup_with_fixtures
381
+ alias_method :setup_with_fixtures, :blank_setup
382
+ alias_method :setup, :blank_setup
383
+
384
+ def blank_teardown; end
385
+ alias_method :ar_teardown_with_fixtures, :teardown_with_fixtures
386
+ alias_method :teardown_with_fixtures, :blank_teardown
387
+ alias_method :teardown, :blank_teardown
388
+
389
+ def test_no_rollback_in_teardown_unless_transaction_active
390
+ assert_equal 0, Thread.current['open_transactions']
391
+ assert_raise(RuntimeError) { ar_setup_with_fixtures }
392
+ assert_equal 0, Thread.current['open_transactions']
393
+ assert_nothing_raised { ar_teardown_with_fixtures }
394
+ assert_equal 0, Thread.current['open_transactions']
395
+ end
396
+
397
+ private
398
+ def load_fixtures
399
+ raise 'argh'
400
+ end
401
+ end