|
1 | 1 | require 'spec_helper' |
2 | 2 | require 'pry' |
3 | 3 | describe InheritanceIntegerType do |
| 4 | + [3,5].each do |major_version| |
| 5 | + let(:base) { Base.create(name: "Hello") } |
| 6 | + let(:left) { LeftChild.create(name: "Hello") } |
| 7 | + let(:deep) { DeepChild.create(name: "Hello") } |
| 8 | + |
| 9 | + before { allow(ActiveRecord::VERSION).to receive(:MAJOR).and_return(major_version) } |
| 10 | + |
| 11 | + describe "The parent" do |
| 12 | + subject { base } |
| 13 | + it { is_expected.to be_persisted } |
| 14 | + it "has no type" do |
| 15 | + expect(subject.type).to be_nil |
| 16 | + end |
| 17 | + it { is_expected.to eql Base.first } |
| 18 | + end |
4 | 19 |
|
5 | | - let(:base) { Base.create(name: "Hello") } |
6 | | - let(:left) { LeftChild.create(name: "Hello") } |
7 | | - let(:deep) { DeepChild.create(name: "Hello") } |
| 20 | + describe "The inherited classes" do |
| 21 | + subject { left } |
| 22 | + it { is_expected.to be_persisted } |
| 23 | + it { is_expected.to eql LeftChild.first } |
| 24 | + end |
8 | 25 |
|
9 | | - describe "The parent" do |
10 | | - subject { base } |
11 | | - it { is_expected.to be_persisted } |
12 | | - it "has no type" do |
13 | | - expect(subject.type).to be_nil |
| 26 | + describe "The deep inherited classes" do |
| 27 | + subject { deep } |
| 28 | + it { is_expected.to be_persisted } |
| 29 | + it { is_expected.to eql DeepChild.first } |
14 | 30 | end |
15 | | - it { is_expected.to eql Base.first } |
16 | | - end |
17 | 31 |
|
18 | | - describe "The inherited classes" do |
19 | | - subject { left } |
20 | | - it { is_expected.to be_persisted } |
21 | | - it { is_expected.to eql LeftChild.first } |
22 | | - end |
| 32 | + describe "Belongs to associations" do |
23 | 33 |
|
24 | | - describe "The deep inherited classes" do |
25 | | - subject { deep } |
26 | | - it { is_expected.to be_persisted } |
27 | | - it { is_expected.to eql DeepChild.first } |
28 | | - end |
| 34 | + let(:belong) { BelongsTo.create(base: base, left_child: left) } |
| 35 | + subject { belong } |
29 | 36 |
|
30 | | - describe "Belongs to associations" do |
| 37 | + it "properly assocaites the base class" do |
| 38 | + expect(subject.base).to eql base |
| 39 | + end |
31 | 40 |
|
32 | | - let(:belong) { BelongsTo.create(base: base, left_child: left) } |
33 | | - subject { belong } |
| 41 | + it "properly assocaites the children class" do |
| 42 | + expect(subject.left_child).to eql left |
| 43 | + end |
34 | 44 |
|
35 | | - it "properly assocaites the base class" do |
36 | | - expect(subject.base).to eql base |
37 | | - end |
38 | 45 |
|
39 | | - it "properly assocaites the children class" do |
40 | | - expect(subject.left_child).to eql left |
41 | 46 | end |
42 | 47 |
|
43 | | - |
44 | | - end |
45 | | - |
46 | | - describe "Has many associations" do |
47 | | - let(:other) { Other.create } |
48 | | - before do |
49 | | - [base, left, deep].each{|a| a.update_attributes(other: other) } |
| 48 | + describe "Has many associations" do |
| 49 | + let(:other) { Other.create } |
| 50 | + before do |
| 51 | + [base, left, deep].each{|a| a.update_attributes(other: other) } |
| 52 | + end |
| 53 | + subject { other } |
| 54 | + it "properly finds the classes through the association" do |
| 55 | + expect(other.bases).to match_array [base, left, deep] |
| 56 | + end |
50 | 57 | end |
51 | | - subject { other } |
52 | | - it "properly finds the classes through the association" do |
53 | | - expect(other.bases).to match_array [base, left, deep] |
54 | | - end |
55 | | - |
56 | 58 | end |
57 | | - |
58 | 59 | end |
0 commit comments