Created
December 11, 2012 14:24
-
-
Save andreareginato/4258925 to your computer and use it in GitHub Desktop.
Lelylan automatic pending status definition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'when updates a property' do | |
let(:resource) { FactoryGirl.create :device } | |
let(:property_id) { resource.properties.first.id } | |
describe 'when :pending was false' do | |
before { resource.update_attributes(properties_attributes: [{ id: property_id, pending: false }]) } | |
describe 'when updates :value' do | |
let(:properties) { [ { id: property_id, value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
end | |
describe 'when updates :expected_value' do | |
let(:properties) { [ { id: property_id, expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == true } | |
its(:value) { should == '0' } | |
end | |
describe 'when updates :value and :expected_value' do | |
describe 'when they are equal' do | |
let(:properties) { [ { id: property_id, value: '100', expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
end | |
describe 'when they are different' do | |
let(:properties) { [ { id: property_id, value: '50', expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == true } | |
end | |
end | |
end | |
describe 'when :pending was true' do | |
before { resource.update_attributes(properties_attributes: [{ id: property_id, pending: true, expected_value: '100' }]) } | |
describe 'when updates :value' do | |
describe 'when :value and :expected_value are equal' do | |
let(:properties) { [ { id: property_id, value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
end | |
describe 'when :value and :expected_value are not equal' do | |
let(:properties) { [ { id: property_id, value: '50' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == true } | |
end | |
end | |
describe 'when updates :expected_value' do | |
let(:properties) { [ { id: property_id, expected_value: '50' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == true } | |
its(:value) { should == 'off' } | |
end | |
describe 'when updates :value and :expected_value' do | |
describe 'when they are equal' do | |
let(:properties) { [ { id: property_id, value: '100', expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
end | |
describe 'when they are different' do | |
let(:properties) { [ { id: property_id, value: '50', expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == true } | |
end | |
end | |
end | |
describe 'when a physical device is not connected' do | |
before { resource.update_attributes(physical: nil) } | |
describe 'when updates :value' do | |
let(:properties) { [ { id: property_id, value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
end | |
describe 'when updates :expected_value' do | |
let(:properties) { [ { id: property_id, expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
its(:value) { should == '100' } | |
end | |
describe 'when updates :value and :expected_value' do | |
let(:properties) { [ { id: property_id, value: '50', expected_value: '100' } ] } | |
before { resource.update_attributes(properties_attributes: properties) } | |
subject { resource.properties.first } | |
its(:pending) { should == false } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment