polymorpheus 2.2.0 → 3.3.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.
@@ -1,115 +0,0 @@
1
- shared_examples_for "mysql2 migration statements" do
2
- describe "#add_polymorphic_constraints" do
3
- before { connection.add_polymorphic_constraints(table, columns, options) }
4
-
5
- specify do
6
- clean_sql(sql.join("\n")).should == clean_sql(full_constraints_sql)
7
- end
8
- end
9
-
10
- describe "#add_polymorphic_triggers" do
11
- before { connection.add_polymorphic_triggers(table, columns.keys) }
12
-
13
- specify do
14
- clean_sql(sql.join("\n")).should == clean_sql(trigger_sql)
15
- end
16
- end
17
-
18
- describe "#remove_polymorphic_constraints" do
19
- before { connection.remove_polymorphic_constraints(table, columns, options) }
20
-
21
- specify do
22
- clean_sql(sql.join("\n")).should == clean_sql(remove_constraints_sql)
23
- end
24
- end
25
- end
26
-
27
- shared_context "columns with short names" do
28
- let(:table) { 'pets' }
29
- let(:columns) { { 'kitty_id' => 'cats.name', 'dog_id' => 'dogs.id' } }
30
- let(:trigger_sql) do
31
- %{
32
- DROP TRIGGER IF EXISTS pfki_pets_dogid_kittyid
33
- DROP TRIGGER IF EXISTS pfku_pets_dogid_kittyid
34
- CREATE TRIGGER pfki_pets_dogid_kittyid BEFORE INSERT ON pets
35
- FOR EACH ROW
36
- BEGIN
37
- IF(IF(NEW.dog_id IS NULL, 0, 1) + IF(NEW.kitty_id IS NULL, 0, 1)) <> 1 THEN
38
- SET NEW = 'Error';
39
- END IF;
40
- END
41
- CREATE TRIGGER pfku_pets_dogid_kittyid BEFORE UPDATE ON pets
42
- FOR EACH ROW
43
- BEGIN
44
- IF(IF(NEW.dog_id IS NULL, 0, 1) + IF(NEW.kitty_id IS NULL, 0, 1)) <> 1 THEN
45
- SET NEW = 'Error';
46
- END IF;
47
- END
48
- }
49
- end
50
- let(:fkey_sql) do
51
- %{
52
- ALTER TABLE `pets` ADD CONSTRAINT `pets_dog_id_fk` FOREIGN KEY (`dog_id`) REFERENCES `dogs`(id)
53
- ALTER TABLE `pets` ADD CONSTRAINT `pets_kitty_id_fk` FOREIGN KEY (`kitty_id`) REFERENCES `cats`(name)
54
- }
55
- end
56
- let(:unique_key_sql) { '' }
57
- let(:full_constraints_sql) { trigger_sql + unique_key_sql + fkey_sql }
58
- let(:remove_indices_sql) { '' }
59
- let(:remove_constraints_sql) do
60
- %{
61
- DROP TRIGGER IF EXISTS pfki_pets_dogid_kittyid
62
- DROP TRIGGER IF EXISTS pfku_pets_dogid_kittyid
63
- ALTER TABLE `pets` DROP FOREIGN KEY `pets_kitty_id_fk`
64
- ALTER TABLE `pets` DROP FOREIGN KEY `pets_dog_id_fk`
65
- } +
66
- remove_indices_sql
67
- end
68
- end
69
-
70
- shared_context "columns with long names" do
71
- let(:table) { 'bicycles' }
72
- let(:columns) do
73
- { 'im_too_cool_to_vote_and_ill_only_ride_a_fixie' => 'hipster.id',
74
- 'really_im_not_doping_i_just_practice_a_lot' => 'professional.id' }
75
- end
76
- let(:options) { {} }
77
-
78
- let(:trigger_sql) do
79
- %{
80
- DROP TRIGGER IF EXISTS pfki_bicycles_imtoocooltovoteandillonl_reallyimnotdopingijustpr
81
- DROP TRIGGER IF EXISTS pfku_bicycles_imtoocooltovoteandillonl_reallyimnotdopingijustpr
82
- CREATE TRIGGER pfki_bicycles_imtoocooltovoteandillonl_reallyimnotdopingijustpr BEFORE INSERT ON bicycles
83
- FOR EACH ROW
84
- BEGIN
85
- IF(IF(NEW.im_too_cool_to_vote_and_ill_only_ride_a_fixie IS NULL, 0, 1) + IF(NEW.really_im_not_doping_i_just_practice_a_lot IS NULL, 0, 1)) <> 1 THEN
86
- SET NEW = 'Error';
87
- END IF;
88
- END
89
- CREATE TRIGGER pfku_bicycles_imtoocooltovoteandillonl_reallyimnotdopingijustpr BEFORE UPDATE ON bicycles
90
- FOR EACH ROW
91
- BEGIN
92
- IF(IF(NEW.im_too_cool_to_vote_and_ill_only_ride_a_fixie IS NULL, 0, 1) + IF(NEW.really_im_not_doping_i_just_practice_a_lot IS NULL, 0, 1)) <> 1 THEN
93
- SET NEW = 'Error';
94
- END IF;
95
- END
96
- }
97
- end
98
-
99
- let(:fkey_sql) do
100
- %{
101
- ALTER TABLE `bicycles` ADD CONSTRAINT `bicycles_im_too_cool_to_vote_and_ill_only_ride_a_fixie_fk` FOREIGN KEY (`im_too_cool_to_vote_and_ill_only_ride_a_fixie`) REFERENCES `hipster`(id)
102
- ALTER TABLE `bicycles` ADD CONSTRAINT `bicycles_really_im_not_doping_i_just_practice_a_lot_fk` FOREIGN KEY (`really_im_not_doping_i_just_practice_a_lot`) REFERENCES `professional`(id)
103
- }
104
- end
105
-
106
- let(:full_constraints_sql) { trigger_sql + fkey_sql }
107
- let(:remove_constraints_sql) do
108
- %{
109
- DROP TRIGGER IF EXISTS pfki_bicycles_imtoocooltovoteandillonl_reallyimnotdopingijustpr
110
- DROP TRIGGER IF EXISTS pfku_bicycles_imtoocooltovoteandillonl_reallyimnotdopingijustpr
111
- ALTER TABLE `bicycles` DROP FOREIGN KEY `bicycles_im_too_cool_to_vote_and_ill_only_ride_a_fixie_fk`
112
- ALTER TABLE `bicycles` DROP FOREIGN KEY `bicycles_really_im_not_doping_i_just_practice_a_lot_fk`
113
- }
114
- end
115
- end
@@ -1,32 +0,0 @@
1
- ActiveRecord::Base.establish_connection({
2
- adapter: 'mysql2',
3
- username: 'travis',
4
- database: 'polymorpheus_test'
5
- })
6
-
7
- ActiveRecord::Base.connection.tables.each do |table|
8
- ActiveRecord::Base.connection.drop_table table
9
- end
10
-
11
- ActiveRecord::Schema.define do
12
- create_table :heros
13
- create_table :villains
14
- create_table :superheros
15
- create_table :alien_demigods
16
- create_table :supervillains
17
- create_table :trees
18
-
19
- create_table :story_arcs do |t|
20
- t.integer :hero_id
21
- t.integer :villain_id
22
- t.integer :battle_id
23
- t.integer :issue_id
24
- end
25
-
26
- create_table :battles
27
-
28
- create_table :superpowers do |t|
29
- t.integer :superhero_id
30
- t.integer :supervillain_id
31
- end
32
- end