joinfix 0.1.0 → 0.1.1

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.
Files changed (40) hide show
  1. data/README +1 -1
  2. data/lib/joinfix/fixtures.rb +130 -155
  3. data/lib/joinfix/fixtures_class.rb +95 -30
  4. data/lib/joinfix.rb +108 -45
  5. data/rails/log/development.log +71 -0
  6. data/rails/log/test.log +85 -0
  7. data/rails/test/test_helper.rb +1 -0
  8. data/test/belongs_to_polymorphic_test.rb +78 -0
  9. data/test/belongs_to_test.rb +135 -44
  10. data/test/belongs_to_with_options_test.rb +57 -0
  11. data/test/has_and_belongs_to_many_test.rb +36 -36
  12. data/test/has_and_belongs_to_many_with_options_test.rb +84 -0
  13. data/test/has_many_as_test.rb +66 -0
  14. data/test/has_many_test.rb +33 -69
  15. data/test/has_many_through_test.rb +79 -0
  16. data/test/has_many_through_with_options_test.rb +85 -0
  17. data/test/has_many_with_options_test.rb +63 -0
  18. data/test/has_one_test.rb +26 -27
  19. data/test/has_one_with_options_test.rb +57 -0
  20. data/test/joinfix_test.rb +5 -5
  21. data/test/joinfix_test_helper.rb +76 -16
  22. data/test/missing_fixture_test.rb +54 -0
  23. data/test/nested_test.rb +13 -6
  24. data/test/todo +15 -0
  25. metadata +48 -51
  26. data/test/fixtures/as_children.yml +0 -0
  27. data/test/fixtures/bt_children.yml +0 -0
  28. data/test/fixtures/bt_parents.yml +0 -30
  29. data/test/fixtures/habtm_children.yml +0 -0
  30. data/test/fixtures/habtm_children_habtm_parents.yml +0 -0
  31. data/test/fixtures/habtm_joins.yml +0 -0
  32. data/test/fixtures/habtm_parents.yml +0 -18
  33. data/test/fixtures/hm_children.yml +0 -0
  34. data/test/fixtures/hm_joins.yml +0 -0
  35. data/test/fixtures/hm_parents.yml +0 -34
  36. data/test/fixtures/ho_children.yml +0 -0
  37. data/test/fixtures/ho_parents.yml +0 -14
  38. data/test/fixtures/no_join_fixes.yml +0 -4
  39. data/test/fixtures/omap_no_join_fixes.yml +0 -7
  40. data/test/fixtures/polymorphic_children.yml +0 -0
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/joinfix_test_helper'
2
+
3
+ #
4
+ # belongs_to with configuration options
5
+ #
6
+
7
+ class BelongsToWithOptionsMigration < ActiveRecord::Migration
8
+ def self.up
9
+ create_table :bt_with_options_parents do |t|
10
+ t.column :field, :string
11
+ t.column :alternate, :integer
12
+ end
13
+ create_table :bt_with_options_children do |t|
14
+ t.column :field, :string
15
+ end
16
+ end
17
+
18
+ def self.down
19
+ drop_table :bt_with_options_parents
20
+ drop_table :bt_with_options_children
21
+ end
22
+ end
23
+
24
+ class BtWithOptionsParent < ActiveRecord::Base
25
+ belongs_to :child,
26
+ :foreign_key => "alternate",
27
+ :class_name => "BtWithOptionsChild"
28
+ end
29
+
30
+ class BtWithOptionsChild < ActiveRecord::Base
31
+ end
32
+
33
+ class BelongsToWithOptionsTest < Test::Unit::TestCase
34
+ fixtures :bt_with_options_parents, :bt_with_options_children
35
+
36
+ def test_belongs_to_with_options
37
+ setup_fixtures(
38
+ :bt_with_options_parents => %Q{
39
+ parent_entry:
40
+ field: parent value
41
+ child:
42
+ child_entry:
43
+ field: child value},
44
+ :bt_with_options_children => "")
45
+
46
+ assert_fixtures(
47
+ :bt_with_options_parents => %Q{
48
+ parent_entry:
49
+ id: 1
50
+ alternate: 1
51
+ field: parent value},
52
+ :bt_with_options_children => %Q{
53
+ child_entry:
54
+ id: 1
55
+ field: child value})
56
+ end
57
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/joinfix_test_helper'
2
2
 
3
- class HabtmMigration < ActiveRecord::Migration
3
+ class HasAndBelongsToManyMigration < ActiveRecord::Migration
4
4
  def self.up
5
5
  create_table :habtm_parents do |t|
6
6
  t.column :field, :string
@@ -12,27 +12,17 @@ class HabtmMigration < ActiveRecord::Migration
12
12
  t.column :habtm_parent_id, :integer
13
13
  t.column :habtm_child_id, :integer
14
14
  end
15
- create_table :habtm_joins do |t|
16
- t.column :join_parent_id, :integer
17
- t.column :join_child_id, :integer
18
- end
19
15
  end
20
16
 
21
17
  def self.down
22
18
  drop_table :habtm_parents
23
19
  drop_table :habtm_children
24
20
  drop_table :habtm_children_habtm_parents
25
- drop_table :habtm_joins
26
21
  end
27
22
  end
28
23
 
29
24
  class HabtmParent < ActiveRecord::Base
30
25
  has_and_belongs_to_many :habtm_children
31
- has_and_belongs_to_many :children,
32
- :foreign_key => "join_parent_id",
33
- :association_foreign_key => "join_child_id",
34
- :class_name => "HabtmChild",
35
- :join_table => :habtm_joins
36
26
  end
37
27
 
38
28
  class HabtmChild < ActiveRecord::Base
@@ -41,32 +31,42 @@ end
41
31
  class HabtmChildrenHabtmParent < ActiveRecord::Base
42
32
  end
43
33
 
44
- class HabtmJoin < ActiveRecord::Base
45
- end
46
-
47
34
  class HasAndBelongsToManyTest < Test::Unit::TestCase
48
- fixtures :habtm_parents, :habtm_children, :habtm_children_habtm_parents, :habtm_joins
49
-
50
- def setup
51
- end
52
-
53
- def teardown
54
- end
55
-
56
- def test_has_and_belongs_to_many
57
- database_test(HabtmMigration) do
58
- entry = habtm_parents(:without_children)
59
- assert_equal "without_children", entry.field
60
- assert entry.habtm_children.empty?
61
- assert entry.children.empty?
62
-
63
- entry = habtm_parents(:with_habtm_children)
64
- assert_equal "with_habtm_children", entry.field
65
- assert_equal ["1","2"], entry.habtm_children.collect {|e| e.field}.sort
35
+ fixtures :habtm_parents, :habtm_children, :habtm_children_habtm_parents
36
+
37
+ def test_habtm
38
+ setup_fixtures(
39
+ :habtm_parents => %Q{
40
+ parent_entry:
41
+ field: parent value
42
+ habtm_children:
43
+ - child_one:
44
+ field: one
45
+ - child_two:
46
+ field: two},
47
+ :habtm_children => "",
48
+ :habtm_children_habtm_parents => "")
66
49
 
67
- entry = habtm_parents(:with_children)
68
- assert_equal "with_children", entry.field
69
- assert_equal ["3","4"], entry.children.collect {|e| e.field}.sort
70
- end
50
+ assert_fixtures(
51
+ :habtm_parents => %Q{
52
+ parent_entry:
53
+ id: 1
54
+ field: parent value},
55
+ :habtm_children => %Q{
56
+ child_one:
57
+ id: 1
58
+ field: one
59
+ child_two:
60
+ id: 2
61
+ field: two},
62
+ :habtm_children_habtm_parents => %Q{
63
+ child_one_parent_entry:
64
+ id: 1
65
+ habtm_parent_id: 1
66
+ habtm_child_id: 1
67
+ child_two_parent_entry:
68
+ id: 2
69
+ habtm_parent_id: 1
70
+ habtm_child_id: 2 })
71
71
  end
72
72
  end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/joinfix_test_helper'
2
+
3
+ #
4
+ # Habtm with options
5
+ #
6
+
7
+ class HasAndBelongsToManyWithOptionsMigration < ActiveRecord::Migration
8
+ def self.up
9
+ create_table :habtm_with_options_parents do |t|
10
+ t.column :field, :string
11
+ end
12
+ create_table :habtm_with_options_children do |t|
13
+ t.column :field, :string
14
+ end
15
+ create_table :habtm_joins do |t|
16
+ t.column :field, :string
17
+ t.column :alternate_parent, :integer
18
+ t.column :alternate_child, :integer
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :habtm_with_options_parents
24
+ drop_table :habtm_with_options_children
25
+ drop_table :habtm_joins
26
+ end
27
+ end
28
+
29
+ class HabtmWithOptionsParent < ActiveRecord::Base
30
+ has_and_belongs_to_many :children,
31
+ :foreign_key => "alternate_parent",
32
+ :association_foreign_key => "alternate_child",
33
+ :class_name => "HabtmWithOptionsChild",
34
+ :join_table => :habtm_joins
35
+ end
36
+
37
+ class HabtmWithOptionsChild < ActiveRecord::Base
38
+ end
39
+
40
+ class HabtmJoin < ActiveRecord::Base
41
+ end
42
+
43
+ class HasAndBelongsToManyWithOptionsTest < Test::Unit::TestCase
44
+ fixtures :habtm_with_options_parents, :habtm_with_options_children, :habtm_joins
45
+
46
+ def test_habtm_with_options
47
+ setup_fixtures(
48
+ :habtm_with_options_parents => %Q{
49
+ parent_entry:
50
+ field: parent value
51
+ children:
52
+ - child_one:
53
+ field: one
54
+ - child_two:
55
+ field: two},
56
+ :habtm_with_options_children => "",
57
+ :habtm_joins => "
58
+ child_one_parent_entry:
59
+ field: one value")
60
+
61
+ assert_fixtures(
62
+ :habtm_with_options_parents => %Q{
63
+ parent_entry:
64
+ id: 1
65
+ field: parent value},
66
+ :habtm_with_options_children => %Q{
67
+ child_one:
68
+ id: 1
69
+ field: one
70
+ child_two:
71
+ id: 2
72
+ field: two},
73
+ :habtm_joins => %Q{
74
+ child_one_parent_entry:
75
+ id: 1
76
+ field: one value
77
+ alternate_parent: 1
78
+ alternate_child: 1
79
+ child_two_parent_entry:
80
+ id: 2
81
+ alternate_parent: 1
82
+ alternate_child: 2 })
83
+ end
84
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/joinfix_test_helper'
2
+
3
+ #
4
+ # hm as
5
+ #
6
+
7
+ class HasManyAsMigration < ActiveRecord::Migration
8
+ def self.up
9
+ create_table :hm_as_parents do |t|
10
+ t.column :field, :string
11
+ end
12
+ create_table :hm_as_children do |t|
13
+ t.column :polymorphic_parent_id, :integer
14
+ t.column :polymorphic_parent_type, :string
15
+ t.column :field, :string
16
+ end
17
+ end
18
+
19
+ def self.down
20
+ drop_table :hm_as_parents
21
+ drop_table :hm_as_children
22
+ end
23
+ end
24
+
25
+ class HmAsParent < ActiveRecord::Base
26
+ has_many :hm_as_children,
27
+ :as => :polymorphic_parent
28
+ end
29
+
30
+ class HmAsChild < ActiveRecord::Base
31
+ belongs_to :polymorphic_parent, :polymorphic => true
32
+ end
33
+
34
+ class HasManyAsTest < Test::Unit::TestCase
35
+ fixtures :hm_as_parents, :hm_as_children
36
+
37
+ def test_has_many_as
38
+ setup_fixtures(
39
+ :hm_as_parents => %Q{
40
+ parent_entry:
41
+ field: parent value
42
+ hm_as_children:
43
+ child_one:
44
+ field: one
45
+ child_two:
46
+ field: two},
47
+ :hm_as_children => "")
48
+
49
+ assert_fixtures(
50
+ :hm_as_parents => %Q{
51
+ parent_entry:
52
+ id: 1
53
+ field: parent value},
54
+ :hm_as_children => %Q{
55
+ child_one:
56
+ id: 1
57
+ polymorphic_parent_id: 1
58
+ polymorphic_parent_type: HmAsParent
59
+ field: one
60
+ child_two:
61
+ id: 2
62
+ polymorphic_parent_id: 1
63
+ polymorphic_parent_type: HmAsParent
64
+ field: two})
65
+ end
66
+ end
@@ -1,6 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/joinfix_test_helper'
2
2
 
3
- class HmMigration < ActiveRecord::Migration
3
+ #
4
+ # has many test
5
+ #
6
+
7
+ class HasManyMigration < ActiveRecord::Migration
4
8
  def self.up
5
9
  create_table :hm_parents do |t|
6
10
  t.column :field, :string
@@ -8,90 +12,50 @@ class HmMigration < ActiveRecord::Migration
8
12
  create_table :hm_children do |t|
9
13
  t.column :field, :string
10
14
  t.column :hm_parent_id, :integer
11
- t.column :alt_id, :integer
12
- end
13
- create_table :hm_joins do |t|
14
- t.column :hm_parent_id, :integer
15
- t.column :hm_child_id, :integer
16
15
  end
17
- create_table :as_children do |t|
18
- t.column :polymorphic_parent_id, :integer
19
- t.column :polymorphic_parent_type, :string
20
- t.column :field, :string
21
- end
22
16
  end
23
17
 
24
18
  def self.down
25
19
  drop_table :hm_parents
26
20
  drop_table :hm_children
27
- drop_table :hm_joins
28
- drop_table :as_children
29
21
  end
30
22
  end
31
23
 
32
24
  class HmParent < ActiveRecord::Base
33
25
  has_many :hm_children
34
- has_many :children,
35
- :foreign_key => "alt_id",
36
- :class_name => "HmChild"
37
-
38
- has_many :hm_joins
39
- has_many :join_children,
40
- :through => :hm_joins,
41
- :source => :hm_child
42
-
43
- has_many :through_children,
44
- :through => :hm_joins,
45
- :source => :hm_child
46
-
47
- has_many :as_children,
48
- :as => :polymorphic_parent
49
26
  end
50
27
 
51
28
  class HmChild < ActiveRecord::Base
52
29
  end
53
30
 
54
- class HmJoin < ActiveRecord::Base
55
- belongs_to :hm_child
56
- end
57
-
58
- class AsChild < ActiveRecord::Base
59
- belongs_to :polymorphic_parent, :polymorphic => true
60
- end
61
-
62
31
  class HasManyTest < Test::Unit::TestCase
63
- fixtures :hm_parents, :hm_children, :hm_joins, :as_children
64
-
65
- def setup
66
- end
67
-
68
- def teardown
69
- end
70
-
32
+ fixtures :hm_parents, :hm_children
33
+
71
34
  def test_has_many
72
- database_test(HmMigration) do
73
- entry = hm_parents(:without_children)
74
- assert_equal "without_children", entry.field
75
- assert entry.hm_children.empty?
76
- assert entry.children.empty?
77
- assert entry.join_children.empty?
78
- assert entry.as_children.empty?
79
-
80
- entry = hm_parents(:with_hm_children)
81
- assert_equal "with_hm_children", entry.field
82
- assert_equal ["1","2"], entry.hm_children.collect {|e| e.field}.sort
83
-
84
- entry = hm_parents(:with_children)
85
- assert_equal "with_children", entry.field
86
- assert_equal ["3","4"], entry.children.collect {|e| e.field}.sort
87
-
88
- entry = hm_parents(:with_through_children)
89
- assert_equal "with_through_children", entry.field
90
- assert_equal ["5","6"], entry.join_children.collect {|e| e.field}.sort
91
-
92
- entry = hm_parents(:with_as_children)
93
- assert_equal "with_as_children", entry.field
94
- assert_equal ["7","8"], entry.as_children.collect {|e| e.field}.sort
95
- end
35
+ setup_fixtures(
36
+ :hm_parents => %Q{
37
+ parent_entry:
38
+ field: parent value
39
+ hm_children:
40
+ - child_one:
41
+ field: one
42
+ - child_two:
43
+ field: two},
44
+ :hm_children => "")
45
+
46
+ assert_fixtures(
47
+ :hm_parents => %Q{
48
+ parent_entry:
49
+ id: 1
50
+ field: parent value},
51
+ :hm_children => %Q{
52
+ child_one:
53
+ id: 1
54
+ hm_parent_id: 1
55
+ field: one
56
+ child_two:
57
+ id: 2
58
+ hm_parent_id: 1
59
+ field: two})
96
60
  end
97
- end
61
+ end
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/joinfix_test_helper'
2
+
3
+ #
4
+ # hm through
5
+ #
6
+
7
+ class HasManyThroughMigration < ActiveRecord::Migration
8
+ def self.up
9
+ create_table :hm_through_parents do |t|
10
+ t.column :field, :string
11
+ end
12
+ create_table :hm_through_children do |t|
13
+ t.column :field, :string
14
+ end
15
+ create_table :hm_through_joins do |t|
16
+ t.column :hm_through_parent_id, :integer
17
+ t.column :hm_through_child_id, :integer
18
+ end
19
+ end
20
+
21
+ def self.down
22
+ drop_table :hm_through_parents
23
+ drop_table :hm_through_children
24
+ drop_table :hm_through_joins
25
+ end
26
+ end
27
+
28
+
29
+ class HmThroughParent < ActiveRecord::Base
30
+ has_many :hm_through_joins
31
+ has_many :hm_through_children, :through => :hm_through_joins
32
+ end
33
+
34
+ class HmThroughChild < ActiveRecord::Base
35
+ end
36
+
37
+ class HmThroughJoin < ActiveRecord::Base
38
+ belongs_to :hm_through_child
39
+ end
40
+
41
+ class HasManyThroughTest < Test::Unit::TestCase
42
+ fixtures :hm_through_parents, :hm_through_children, :hm_through_joins
43
+
44
+ def test_has_many_through
45
+ setup_fixtures(
46
+ :hm_through_parents => %Q{
47
+ parent_entry:
48
+ field: parent value
49
+ hm_through_children:
50
+ - child_one:
51
+ field: one
52
+ - child_two:
53
+ field: two},
54
+ :hm_through_children => "",
55
+ :hm_through_joins => "")
56
+
57
+ assert_fixtures(
58
+ :hm_through_parents => %Q{
59
+ parent_entry:
60
+ id: 1
61
+ field: parent value},
62
+ :hm_through_children => %Q{
63
+ child_one:
64
+ id: 1
65
+ field: one
66
+ child_two:
67
+ id: 2
68
+ field: two},
69
+ :hm_through_joins => %Q{
70
+ child_one_parent_entry:
71
+ id: 1
72
+ hm_through_parent_id: 1
73
+ hm_through_child_id: 1
74
+ child_two_parent_entry:
75
+ id: 2
76
+ hm_through_parent_id: 1
77
+ hm_through_child_id: 2})
78
+ end
79
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/joinfix_test_helper'
2
+
3
+ #
4
+ # hm through
5
+ #
6
+
7
+ class HasManyThroughWithOptionsMigration < ActiveRecord::Migration
8
+ def self.up
9
+ create_table :hm_through_with_options_parents do |t|
10
+ t.column :field, :string
11
+ end
12
+ create_table :hm_through_with_options_children do |t|
13
+ t.column :field, :string
14
+ end
15
+ create_table :hm_through_with_options_joins do |t|
16
+ t.column :alternate_parent, :integer
17
+ t.column :alternate_child, :integer
18
+ end
19
+ end
20
+
21
+ def self.down
22
+ drop_table :hm_through_with_options_parents
23
+ drop_table :hm_through_with_options_children
24
+ drop_table :hm_through_with_options_joins
25
+ end
26
+ end
27
+
28
+
29
+ class HmThroughWithOptionsParent < ActiveRecord::Base
30
+ has_many :through_joins,
31
+ :class_name => 'HmThroughWithOptionsJoin',
32
+ :foreign_key => 'alternate_parent'
33
+ has_many :children,
34
+ :through => :through_joins,
35
+ :source => :through_child
36
+ end
37
+
38
+ class HmThroughWithOptionsChild < ActiveRecord::Base
39
+ end
40
+
41
+ class HmThroughWithOptionsJoin < ActiveRecord::Base
42
+ belongs_to :through_child,
43
+ :class_name => 'HmThroughWithOptionsChild',
44
+ :foreign_key => 'alternate_child'
45
+ end
46
+
47
+ class HasManyThroughWithOptionsTest < Test::Unit::TestCase
48
+ fixtures :hm_through_with_options_parents, :hm_through_with_options_children, :hm_through_with_options_joins
49
+
50
+ def test_has_many_through_with_options
51
+ setup_fixtures(
52
+ :hm_through_with_options_parents => %Q{
53
+ parent_entry:
54
+ field: parent value
55
+ children:
56
+ - child_one:
57
+ field: one
58
+ - child_two:
59
+ field: two},
60
+ :hm_through_with_options_children => "",
61
+ :hm_through_with_options_joins => "")
62
+
63
+ assert_fixtures(
64
+ :hm_through_with_options_parents => %Q{
65
+ parent_entry:
66
+ id: 1
67
+ field: parent value},
68
+ :hm_through_with_options_children => %Q{
69
+ child_one:
70
+ id: 1
71
+ field: one
72
+ child_two:
73
+ id: 2
74
+ field: two},
75
+ :hm_through_with_options_joins => %Q{
76
+ child_one_parent_entry:
77
+ id: 1
78
+ alternate_parent: 1
79
+ alternate_child: 1
80
+ child_two_parent_entry:
81
+ id: 2
82
+ alternate_parent: 1
83
+ alternate_child: 2})
84
+ end
85
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/joinfix_test_helper'
2
+
3
+ #
4
+ # hm with options
5
+ #
6
+
7
+ class HasManyWithOptionsMigration < ActiveRecord::Migration
8
+ def self.up
9
+ create_table :hm_with_options_parents do |t|
10
+ t.column :field, :string
11
+ end
12
+ create_table :hm_with_options_children do |t|
13
+ t.column :field, :string
14
+ t.column :alternate, :integer
15
+ end
16
+ end
17
+
18
+ def self.down
19
+ drop_table :hm_with_options_parents
20
+ drop_table :hm_with_options_children
21
+ end
22
+ end
23
+
24
+ class HmWithOptionsParent < ActiveRecord::Base
25
+ has_many :children,
26
+ :foreign_key => "alternate",
27
+ :class_name => "HmWithOptionsChild"
28
+ end
29
+
30
+ class HmWithOptionsChild < ActiveRecord::Base
31
+ end
32
+
33
+ class HasManyWithOptionsTest < Test::Unit::TestCase
34
+ fixtures :hm_with_options_parents, :hm_with_options_children
35
+
36
+ def test_has_many_with_options
37
+ setup_fixtures(
38
+ :hm_with_options_parents => %Q{
39
+ parent_entry:
40
+ field: parent value
41
+ children:
42
+ - child_one:
43
+ field: one
44
+ - child_two:
45
+ field: two},
46
+ :hm_with_options_children => "")
47
+
48
+ assert_fixtures(
49
+ :hm_with_options_parents => %Q{
50
+ parent_entry:
51
+ id: 1
52
+ field: parent value},
53
+ :hm_with_options_children => %Q{
54
+ child_one:
55
+ id: 1
56
+ alternate: 1
57
+ field: one
58
+ child_two:
59
+ id: 2
60
+ alternate: 1
61
+ field: two})
62
+ end
63
+ end