joinfix 0.1.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/MIT-LICENSE +21 -0
- data/README +86 -0
- data/TEST_README +44 -0
- data/lib/joinfix/fixture.rb +29 -0
- data/lib/joinfix/fixtures.rb +271 -0
- data/lib/joinfix/fixtures_class.rb +102 -0
- data/lib/joinfix.rb +208 -0
- data/rails/README +182 -0
- data/rails/Rakefile +10 -0
- data/rails/app/controllers/application.rb +7 -0
- data/rails/app/helpers/application_helper.rb +3 -0
- data/rails/app/models/group.rb +4 -0
- data/rails/app/models/inner_child.rb +4 -0
- data/rails/app/models/nested_child.rb +4 -0
- data/rails/app/models/nested_parent.rb +4 -0
- data/rails/app/models/user.rb +4 -0
- data/rails/app/models/user_group.rb +5 -0
- data/rails/config/boot.rb +45 -0
- data/rails/config/database.yml +36 -0
- data/rails/config/environment.rb +60 -0
- data/rails/config/environments/development.rb +21 -0
- data/rails/config/environments/production.rb +18 -0
- data/rails/config/environments/test.rb +19 -0
- data/rails/config/routes.rb +23 -0
- data/rails/db/migrate/001_create_nested_parents.rb +12 -0
- data/rails/db/migrate/002_create_nested_children.rb +12 -0
- data/rails/db/migrate/003_create_inner_children.rb +12 -0
- data/rails/db/migrate/004_create_users.rb +11 -0
- data/rails/db/migrate/005_create_groups.rb +11 -0
- data/rails/db/migrate/006_create_user_groups.rb +12 -0
- data/rails/db/schema.rb +35 -0
- data/rails/doc/README_FOR_APP +2 -0
- data/rails/public/404.html +30 -0
- data/rails/public/500.html +30 -0
- data/rails/public/dispatch.cgi +10 -0
- data/rails/public/dispatch.fcgi +24 -0
- data/rails/public/dispatch.rb +10 -0
- data/rails/public/favicon.ico +0 -0
- data/rails/public/images/rails.png +0 -0
- data/rails/public/index.html +277 -0
- data/rails/public/javascripts/application.js +2 -0
- data/rails/public/javascripts/controls.js +833 -0
- data/rails/public/javascripts/dragdrop.js +942 -0
- data/rails/public/javascripts/effects.js +1088 -0
- data/rails/public/javascripts/prototype.js +2515 -0
- data/rails/public/robots.txt +1 -0
- data/rails/script/about +3 -0
- data/rails/script/breakpointer +3 -0
- data/rails/script/console +3 -0
- data/rails/script/destroy +3 -0
- data/rails/script/generate +3 -0
- data/rails/script/performance/benchmarker +3 -0
- data/rails/script/performance/profiler +3 -0
- data/rails/script/plugin +3 -0
- data/rails/script/process/inspector +3 -0
- data/rails/script/process/reaper +3 -0
- data/rails/script/process/spawner +3 -0
- data/rails/script/runner +3 -0
- data/rails/script/server +3 -0
- data/rails/test/fixtures/groups.yml +3 -0
- data/rails/test/fixtures/inner_children.yml +2 -0
- data/rails/test/fixtures/nested_children.yml +2 -0
- data/rails/test/fixtures/nested_parents.yml +33 -0
- data/rails/test/fixtures/user_groups.yml +0 -0
- data/rails/test/fixtures/users.yml +20 -0
- data/rails/test/test_helper.rb +29 -0
- data/rails/test/unit/group_test.rb +10 -0
- data/rails/test/unit/inner_child_test.rb +10 -0
- data/rails/test/unit/nested_child_test.rb +10 -0
- data/rails/test/unit/nested_parent_test.rb +24 -0
- data/rails/test/unit/user_group_test.rb +10 -0
- data/rails/test/unit/user_test.rb +12 -0
- data/test/belongs_to_test.rb +77 -0
- data/test/config.yml +5 -0
- data/test/fixtures/as_children.yml +0 -0
- data/test/fixtures/bt_children.yml +0 -0
- data/test/fixtures/bt_parents.yml +30 -0
- data/test/fixtures/habtm_children.yml +0 -0
- data/test/fixtures/habtm_children_habtm_parents.yml +0 -0
- data/test/fixtures/habtm_joins.yml +0 -0
- data/test/fixtures/habtm_parents.yml +18 -0
- data/test/fixtures/hm_children.yml +0 -0
- data/test/fixtures/hm_joins.yml +0 -0
- data/test/fixtures/hm_parents.yml +34 -0
- data/test/fixtures/ho_children.yml +0 -0
- data/test/fixtures/ho_parents.yml +14 -0
- data/test/fixtures/inner_children.yml +2 -0
- data/test/fixtures/nested_children.yml +0 -0
- data/test/fixtures/nested_parents.yml +33 -0
- data/test/fixtures/no_join_fixes.yml +4 -0
- data/test/fixtures/omap_no_join_fixes.yml +7 -0
- data/test/fixtures/polymorphic_children.yml +0 -0
- data/test/has_and_belongs_to_many_test.rb +72 -0
- data/test/has_many_test.rb +97 -0
- data/test/has_one_test.rb +56 -0
- data/test/joinfix_test.rb +287 -0
- data/test/joinfix_test_helper.rb +54 -0
- data/test/joinfix_test_suite.rb +10 -0
- data/test/nested_test.rb +70 -0
- metadata +189 -0
@@ -0,0 +1 @@
|
|
1
|
+
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
|
data/rails/script/about
ADDED
data/rails/script/plugin
ADDED
data/rails/script/runner
ADDED
data/rails/script/server
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
parent_one:
|
2
|
+
field: 1
|
3
|
+
# nesting in the has_many direction
|
4
|
+
nested_children:
|
5
|
+
nested_one:
|
6
|
+
field: 1
|
7
|
+
inner_children:
|
8
|
+
inner_one:
|
9
|
+
field: 1
|
10
|
+
# array of joins, and reference by name
|
11
|
+
nested_parents:
|
12
|
+
- parent_two
|
13
|
+
- parent_three:
|
14
|
+
field: 3
|
15
|
+
# nesting the belongs_to direction
|
16
|
+
inner_child:
|
17
|
+
inner_two:
|
18
|
+
field: 2
|
19
|
+
nested_child:
|
20
|
+
nested_two:
|
21
|
+
field: 2
|
22
|
+
# another version of reference by name
|
23
|
+
nested_parent: parent_two
|
24
|
+
|
25
|
+
# merge and redundancy -- as per the inner_one declaration above
|
26
|
+
parent_two:
|
27
|
+
field: 2
|
28
|
+
inner_child: inner_one
|
29
|
+
|
30
|
+
# reference to an entry defined in another fixture
|
31
|
+
parent_four:
|
32
|
+
field: 4
|
33
|
+
inner_child: inner_three
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
bob:
|
3
|
+
login: bob
|
4
|
+
groups: admin_group
|
5
|
+
|
6
|
+
jane:
|
7
|
+
id: 3
|
8
|
+
login: jane
|
9
|
+
groups:
|
10
|
+
- admin_group
|
11
|
+
- workers:
|
12
|
+
name: worker bees
|
13
|
+
|
14
|
+
samantha:
|
15
|
+
login: sam
|
16
|
+
groups:
|
17
|
+
movers:
|
18
|
+
name: movers
|
19
|
+
shakers:
|
20
|
+
name: shakers
|
@@ -0,0 +1,29 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
require 'joinfix'
|
5
|
+
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
8
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
9
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
10
|
+
# between every test method. Fewer database queries means faster tests.
|
11
|
+
#
|
12
|
+
# Read Mike Clark's excellent walkthrough at
|
13
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
14
|
+
#
|
15
|
+
# Every Active Record database supports transactions except MyISAM tables
|
16
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
17
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
18
|
+
# is recommended.
|
19
|
+
self.use_transactional_fixtures = true
|
20
|
+
|
21
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
22
|
+
# would need people(:david). If you don't want to migrate your existing
|
23
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
24
|
+
# instantiated fixtures translates to a database query per test method),
|
25
|
+
# then set this back to true.
|
26
|
+
self.use_instantiated_fixtures = false
|
27
|
+
|
28
|
+
# Add more helper methods to be used by all tests here...
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class NestedChildTest < Test::Unit::TestCase
|
4
|
+
fixtures :nested_children
|
5
|
+
|
6
|
+
def test_fixtures_without_joins_behave_as_normal
|
7
|
+
nested_three = nested_children(:nested_three)
|
8
|
+
assert_equal nested_three, NestedChild.find_by_field(3)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class NestedParentTest < Test::Unit::TestCase
|
4
|
+
fixtures :nested_parents, :nested_children, :inner_children
|
5
|
+
|
6
|
+
def test_nested_fixtures
|
7
|
+
parent_one= nested_parents(:parent_one)
|
8
|
+
parent_two = nested_parents(:parent_two)
|
9
|
+
parent_three = nested_parents(:parent_three)
|
10
|
+
parent_four = nested_parents(:parent_four)
|
11
|
+
|
12
|
+
query_result = NestedChild.find_by_field(1).nested_parent
|
13
|
+
assert_equal parent_one, query_result
|
14
|
+
|
15
|
+
query_result = NestedParent.find_by_field(1).nested_children.first.inner_children.first.nested_parents
|
16
|
+
assert_equal [parent_two, parent_three], query_result
|
17
|
+
|
18
|
+
query_result = NestedParent.find_by_field(1).inner_child.nested_child.nested_parent
|
19
|
+
assert_equal parent_two, query_result
|
20
|
+
|
21
|
+
query_result = InnerChild.find_by_field(3).nested_parents.first
|
22
|
+
assert_equal parent_four, query_result
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class UserTest < Test::Unit::TestCase
|
4
|
+
fixtures :users, :groups, :user_groups
|
5
|
+
|
6
|
+
def test_joinfix
|
7
|
+
assert_equal "administrators", users(:bob).groups.first.name
|
8
|
+
assert_equal 2, User.find_by_login("jane").groups.count
|
9
|
+
assert_equal 3, UserGroup.find(user_groups(:jane_workers).id).user.id
|
10
|
+
assert_equal users(:samantha), User.find_by_login("sam").groups.find_by_name("movers").users.first
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/joinfix_test_helper'
|
2
|
+
|
3
|
+
class BtMigration < ActiveRecord::Migration
|
4
|
+
def self.up
|
5
|
+
create_table :bt_parents do |t|
|
6
|
+
t.column :field, :string
|
7
|
+
t.column :bt_child_id, :integer
|
8
|
+
t.column :alt_id, :integer
|
9
|
+
t.column :polymorph_id, :integer
|
10
|
+
t.column :polymorph_type, :string
|
11
|
+
end
|
12
|
+
create_table :bt_children do |t|
|
13
|
+
t.column :field, :string
|
14
|
+
end
|
15
|
+
create_table :polymorphic_children do |t|
|
16
|
+
t.column :field, :string
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.down
|
21
|
+
drop_table :bt_parents
|
22
|
+
drop_table :bt_children
|
23
|
+
drop_table :polymorphic_children
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class BtParent < ActiveRecord::Base
|
28
|
+
belongs_to :bt_child
|
29
|
+
belongs_to :child,
|
30
|
+
:foreign_key => "alt_id",
|
31
|
+
:class_name => "BtChild"
|
32
|
+
|
33
|
+
belongs_to :polymorph,
|
34
|
+
:polymorphic => true
|
35
|
+
end
|
36
|
+
|
37
|
+
class BtChild < ActiveRecord::Base
|
38
|
+
end
|
39
|
+
|
40
|
+
class PolymorphicChild < ActiveRecord::Base
|
41
|
+
has_many :bt_parents,
|
42
|
+
:as => :polymorph
|
43
|
+
end
|
44
|
+
|
45
|
+
class BelongsToTest < Test::Unit::TestCase
|
46
|
+
fixtures :bt_parents, :bt_children, :polymorphic_children
|
47
|
+
|
48
|
+
def setup
|
49
|
+
end
|
50
|
+
|
51
|
+
def teardown
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_belongs_to
|
55
|
+
database_test(BtMigration) do
|
56
|
+
entry = bt_parents(:without_child)
|
57
|
+
assert_equal "without_child", entry.field
|
58
|
+
assert_nil entry.bt_child
|
59
|
+
assert_nil entry.child
|
60
|
+
|
61
|
+
entry = bt_parents(:with_bt_child)
|
62
|
+
assert_equal "with_bt_child", entry.field
|
63
|
+
assert_equal "1", entry.bt_child.field
|
64
|
+
assert_nil entry.child
|
65
|
+
|
66
|
+
entry = bt_parents(:with_child)
|
67
|
+
assert_equal "with_child", entry.field
|
68
|
+
assert_nil entry.bt_child
|
69
|
+
assert_equal "2", entry.child.field
|
70
|
+
|
71
|
+
entry = bt_parents(:with_both)
|
72
|
+
assert_equal "with_both", entry.field
|
73
|
+
assert_equal "3", entry.bt_child.field
|
74
|
+
assert_equal "4", entry.child.field
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/config.yml
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
without_child:
|
2
|
+
field: without_child
|
3
|
+
|
4
|
+
with_bt_child:
|
5
|
+
field: with_bt_child
|
6
|
+
bt_child:
|
7
|
+
first:
|
8
|
+
field: 1
|
9
|
+
|
10
|
+
with_child:
|
11
|
+
field: with_child
|
12
|
+
child:
|
13
|
+
second:
|
14
|
+
field: 2
|
15
|
+
|
16
|
+
with_both:
|
17
|
+
field: with_both
|
18
|
+
bt_child:
|
19
|
+
third:
|
20
|
+
field: 3
|
21
|
+
child:
|
22
|
+
fourth:
|
23
|
+
field: 4
|
24
|
+
|
25
|
+
with_polymorph:
|
26
|
+
field: with_polymorphic_child
|
27
|
+
polymorph_type: PolymorphicChild
|
28
|
+
polymorph:
|
29
|
+
fifth:
|
30
|
+
field: 7
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
without_children:
|
2
|
+
field: without_children
|
3
|
+
|
4
|
+
with_habtm_children:
|
5
|
+
field: with_habtm_children
|
6
|
+
habtm_children:
|
7
|
+
first:
|
8
|
+
field: 1
|
9
|
+
second:
|
10
|
+
field: 2
|
11
|
+
|
12
|
+
with_children:
|
13
|
+
field: with_children
|
14
|
+
children:
|
15
|
+
third:
|
16
|
+
field: 3
|
17
|
+
fourth:
|
18
|
+
field: 4
|
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
without_children:
|
2
|
+
field: without_children
|
3
|
+
|
4
|
+
with_hm_children:
|
5
|
+
field: with_hm_children
|
6
|
+
hm_children:
|
7
|
+
first:
|
8
|
+
field: 1
|
9
|
+
second:
|
10
|
+
field: 2
|
11
|
+
|
12
|
+
with_children:
|
13
|
+
field: with_children
|
14
|
+
children:
|
15
|
+
third:
|
16
|
+
field: 3
|
17
|
+
fourth:
|
18
|
+
field: 4
|
19
|
+
|
20
|
+
with_through_children:
|
21
|
+
field: with_through_children
|
22
|
+
through_children:
|
23
|
+
fifth:
|
24
|
+
field: 5
|
25
|
+
sixth:
|
26
|
+
field: 6
|
27
|
+
|
28
|
+
with_as_children:
|
29
|
+
field: with_as_children
|
30
|
+
as_children:
|
31
|
+
seventh:
|
32
|
+
field: 7
|
33
|
+
eighth:
|
34
|
+
field: 8
|
File without changes
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
parent_one:
|
2
|
+
field: 1
|
3
|
+
# nesting in the has_many direction
|
4
|
+
nested_children:
|
5
|
+
nested_one:
|
6
|
+
field: 1
|
7
|
+
inner_children:
|
8
|
+
inner_one:
|
9
|
+
field: 1
|
10
|
+
# array of joins, and reference by name
|
11
|
+
nested_parents:
|
12
|
+
- parent_two
|
13
|
+
- parent_three:
|
14
|
+
field: 3
|
15
|
+
# nesting the belongs_to direction
|
16
|
+
inner_child:
|
17
|
+
inner_two:
|
18
|
+
field: 2
|
19
|
+
nested_child:
|
20
|
+
nested_two:
|
21
|
+
field: 2
|
22
|
+
# another version of reference by name
|
23
|
+
nested_parent: parent_two
|
24
|
+
|
25
|
+
# merge and redundancy -- as per the inner_one declaration above
|
26
|
+
parent_two:
|
27
|
+
field: 2
|
28
|
+
inner_child: inner_one
|
29
|
+
|
30
|
+
# reference to an entry defined in another fixture
|
31
|
+
parent_four:
|
32
|
+
field: 4
|
33
|
+
inner_child: inner_three
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/joinfix_test_helper'
|
2
|
+
|
3
|
+
class HabtmMigration < ActiveRecord::Migration
|
4
|
+
def self.up
|
5
|
+
create_table :habtm_parents do |t|
|
6
|
+
t.column :field, :string
|
7
|
+
end
|
8
|
+
create_table :habtm_children do |t|
|
9
|
+
t.column :field, :string
|
10
|
+
end
|
11
|
+
create_table :habtm_children_habtm_parents do |t|
|
12
|
+
t.column :habtm_parent_id, :integer
|
13
|
+
t.column :habtm_child_id, :integer
|
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
|
+
end
|
20
|
+
|
21
|
+
def self.down
|
22
|
+
drop_table :habtm_parents
|
23
|
+
drop_table :habtm_children
|
24
|
+
drop_table :habtm_children_habtm_parents
|
25
|
+
drop_table :habtm_joins
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class HabtmParent < ActiveRecord::Base
|
30
|
+
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
|
+
end
|
37
|
+
|
38
|
+
class HabtmChild < ActiveRecord::Base
|
39
|
+
end
|
40
|
+
|
41
|
+
class HabtmChildrenHabtmParent < ActiveRecord::Base
|
42
|
+
end
|
43
|
+
|
44
|
+
class HabtmJoin < ActiveRecord::Base
|
45
|
+
end
|
46
|
+
|
47
|
+
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
|
66
|
+
|
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
|
71
|
+
end
|
72
|
+
end
|