spec/lib/amoeba_spec.rb in amoeba-3.1.0 vs spec/lib/amoeba_spec.rb in amoeba-3.2.0

- old
+ new

@@ -174,46 +174,74 @@ # }}} # }}} end end - context 'use if condition in includes and excludes' do + context 'Using a if condition' do before(:all) do require ::File.dirname(__FILE__) + '/../support/data.rb' end before { ::Post.fresh_amoeba } subject { post.amoeba_dup.save! } let(:post) { Post.first } - it 'includes associations with truthy condition' do + it 'includes an association with truthy condition' do ::Post.amoeba do include_association :comments, if: :truthy? end expect { subject }.to change { Comment.count }.by(3) end - it 'does not include associations with false condition' do + it 'does not include an association with a falsey condition' do ::Post.amoeba do include_association :comments, if: :falsey? end expect { subject }.not_to change { Comment.count } end - it 'excludes associations with truthy condition' do + it 'excludes an association with a truthy condition' do ::Post.amoeba do exclude_association :comments, if: :truthy? end expect { subject }.not_to change { Comment.count } end - it 'does not exclude associations with false condition' do + it 'does not exclude an association with a falsey condition' do ::Post.amoeba do exclude_association :comments, if: :falsey? end expect { subject }.to change { Comment.count }.by(3) end + + it 'includes associations from a given array with a truthy condition' do + ::Post.amoeba do + include_association [:comments], if: :truthy? + end + expect { subject }.to change { Comment.count }.by(3) + end + + it 'does not include associations from a given array with a falsey condition' do + ::Post.amoeba do + include_association [:comments], if: :falsey? + end + expect { subject }.not_to change { Comment.count } + end + + it 'does exclude associations from a given array with a truthy condition' do + ::Post.amoeba do + exclude_association [:comments], if: :truthy? + end + expect { subject }.not_to change { Comment.count } + end + + it 'does not exclude associations from a given array with a falsey condition' do + ::Post.amoeba do + exclude_association [:comments], if: :falsey? + end + expect { subject }.to change { Comment.count }.by(3) + end end context 'override' do before :each do ::Image.fresh_amoeba @@ -299,11 +327,11 @@ let(:box) { Box.create } it 'does not fail with a deep inheritance' do sub_sub_product = BoxSubSubProduct.create(title: 'Awesome shoes') another_product = BoxAnotherProduct.create(title: 'Cleaning product') - sub_sub_product.update_attributes(box: box, another_product: another_product) + sub_sub_product.update(box: box, another_product: another_product) expect(box.sub_products.first.another_product.title).to eq('Cleaning product') expect(box.amoeba_dup.sub_products.first.another_product.title).to eq('Cleaning product') end end @@ -318,10 +346,10 @@ stage end subject { stage.amoeba_dup } - it "contains parent association and own associations", :aggregate_failures do + it 'contains parent association and own associations', :aggregate_failures do subject expect { subject.save! }.to change(Listener, :count).by(2). and change(Specialist, :count).by(1). and change(CustomRule, :count).by(1)