diff options
| author | Johan Van Ryseghem | 2018-02-13 15:21:23 +0100 | 
|---|---|---|
| committer | GitHub | 2018-02-13 15:21:23 +0100 | 
| commit | 385a9e1b68f3eea51f71386a8f4856477ba6a273 (patch) | |
| tree | e7edf769665abd43702b8805ff1ae4b106f60379 /spec/support | |
| parent | 84891328d7ea0c3b82ba3fa3a73b7c49f317855e (diff) | |
| parent | c259d7e3e24259e14b4756f181b3a8784d8d1919 (diff) | |
| download | chouette-core-385a9e1b68f3eea51f71386a8f4856477ba6a273.tar.bz2 | |
Merge pull request #216 from af83/5416_checksum_attribute
5416 checksum attribute
Diffstat (limited to 'spec/support')
| -rw-r--r-- | spec/support/checksum_support.rb | 67 | 
1 files changed, 50 insertions, 17 deletions
| diff --git a/spec/support/checksum_support.rb b/spec/support/checksum_support.rb index e02d9f9f3..f8dffb1b7 100644 --- a/spec/support/checksum_support.rb +++ b/spec/support/checksum_support.rb @@ -1,25 +1,23 @@ -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(:separator)  { 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") +    it 'should separate attribute by separator' do +      expect(subject.current_checksum_source).to eq("code_value#{separator}label_value")      end      context 'nil value' do        let(:attributes) { ['code_value', nil] }        it 'should replace nil attributes by default value' do -        source = "code_value#{seperator}#{nil_value}" -        expect(instance.current_checksum_source).to eq(source) +        source = "code_value#{separator}#{nil_value}" +        expect(subject.current_checksum_source).to eq(source)        end      end @@ -27,27 +25,62 @@ shared_examples 'checksum support' do |factory_name|        let(:attributes) { ['code_value', []] }        it 'should convert to nil' do -        source = "code_value#{seperator}#{nil_value}" -        expect(instance.current_checksum_source).to eq(source) +        source = "code_value#{separator}#{nil_value}" +        expect(subject.current_checksum_source).to eq(source) +      end +    end + +    context 'array value' do +      let(:attributes) { [['v1', 'v2', 'v3'], 'code_value'] } + +      it 'should convert to list' do +        source = "v1,v2,v3#{separator}code_value" +        expect(subject.current_checksum_source).to eq(source) +      end +    end + +    context 'array of array value' do +      let(:attributes) { [[['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']], 'code_value'] } + +      it 'should convert to list' do +        source = "(a1,a2,a3),(b1,b2,b3)#{separator}code_value" +        expect(subject.current_checksum_source).to eq(source) +      end +    end + +    context 'array of array value, with empty array' do +      let(:attributes) { [[['a1', 'a2', 'a3'], []], 'code_value'] } + +      it 'should convert to list' do +        source = "(a1,a2,a3),-#{separator}code_value" +        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 + +  it "doesn't change the checksum on save if the source hasn't been changed" do +    checksum = subject.checksum + +    subject.save + +    expect(subject.checksum).to eq(checksum)    end  end | 
