diff options
| author | Xinhui | 2018-01-05 16:43:37 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-02-07 17:09:22 +0100 | 
| commit | 31b7b91b46d2e8f740d2cfd493836219f5a4f42d (patch) | |
| tree | b9353f96f2d47f7b55b85cbe7bbeb5af6082ce7e /spec | |
| parent | 8a5898177d9a793e791a7e1dcb3162f8bf11aecf (diff) | |
| download | chouette-core-31b7b91b46d2e8f740d2cfd493836219f5a4f42d.tar.bz2 | |
Refactoring use subject as factory
Refs #5416
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/chouette/footnote_spec.rb | 12 | ||||
| -rw-r--r-- | spec/support/checksum_support.rb | 24 | 
2 files changed, 17 insertions, 19 deletions
| diff --git a/spec/models/chouette/footnote_spec.rb b/spec/models/chouette/footnote_spec.rb index fc5e5f306..05f55c2f0 100644 --- a/spec/models/chouette/footnote_spec.rb +++ b/spec/models/chouette/footnote_spec.rb @@ -1,12 +1,12 @@  require 'spec_helper'  describe Chouette::Footnote, type: :model do -  let(:footnote) { create(:footnote) } +  subject { create(:footnote) }    it { should validate_presence_of :line }    describe 'data_source_ref' do      it 'should set default if omitted' do -      expect(footnote.data_source_ref).to eq "DATASOURCEREF_EDITION_BOIV" +      expect(subject.data_source_ref).to eq "DATASOURCEREF_EDITION_BOIV"      end      it 'should not set default if not omitted' do @@ -18,16 +18,16 @@ describe Chouette::Footnote, type: :model do    end    describe 'checksum' do -    it_behaves_like 'checksum support', :footnote +    it_behaves_like 'checksum support'      context '#checksum_attributes' do        it 'should return code and label' do -        expected = [footnote.code, footnote.label] -        expect(footnote.checksum_attributes).to include(*expected) +        expected = [subject.code, subject.label] +        expect(subject.checksum_attributes).to include(*expected)        end        it 'should not return other atrributes' do -        expect(footnote.checksum_attributes).to_not include(footnote.updated_at) +        expect(subject.checksum_attributes).to_not include(subject.updated_at)        end      end    end diff --git a/spec/support/checksum_support.rb b/spec/support/checksum_support.rb index e02d9f9f3..9a4475e23 100644 --- a/spec/support/checksum_support.rb +++ b/spec/support/checksum_support.rb @@ -1,17 +1,15 @@ -shared_examples 'checksum support' do |factory_name| -  let(:instance) { create(factory_name) } - +shared_examples 'checksum support' do    describe '#current_checksum_source' do      let(:attributes) { ['code_value', 'label_value'] }      let(:seperator)  { ChecksumSupport::SEPARATOR }      let(:nil_value)  { ChecksumSupport::VALUE_FOR_NIL_ATTRIBUTE }      before do -      allow_any_instance_of(instance.class).to receive(:checksum_attributes).and_return(attributes) +      allow_any_instance_of(subject.class).to receive(:checksum_attributes).and_return(attributes)      end      it 'should separate attribute by seperator' do -      expect(instance.current_checksum_source).to eq("code_value#{seperator}label_value") +      expect(subject.current_checksum_source).to eq("code_value#{seperator}label_value")      end      context 'nil value' do @@ -19,7 +17,7 @@ shared_examples 'checksum support' do |factory_name|        it 'should replace nil attributes by default value' do          source = "code_value#{seperator}#{nil_value}" -        expect(instance.current_checksum_source).to eq(source) +        expect(subject.current_checksum_source).to eq(source)        end      end @@ -28,26 +26,26 @@ shared_examples 'checksum support' do |factory_name|        it 'should convert to nil' do          source = "code_value#{seperator}#{nil_value}" -        expect(instance.current_checksum_source).to eq(source) +        expect(subject.current_checksum_source).to eq(source)        end      end    end    it 'should save checksum on create' do -    expect(instance.checksum).to_not be_nil +    expect(subject.checksum).to_not be_nil    end    it 'should save checksum_source' do -    expect(instance.checksum_source).to_not be_nil +    expect(subject.checksum_source).to_not be_nil    end    it 'should trigger set_current_checksum_source on save' do -    expect(instance).to receive(:set_current_checksum_source).at_least(:once) -    instance.save +    expect(subject).to receive(:set_current_checksum_source).at_least(:once) +    subject.save    end    it 'should trigger update_checksum on save' do -    expect(instance).to receive(:update_checksum).at_least(:once) -    instance.save +    expect(subject).to receive(:update_checksum).at_least(:once) +    subject.save    end  end | 
