Commit 6e10cd8a8e73f4241152b3d61518d3d61fd50d45

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent b42c9613

Reading model.

Signed-off-by: Renan Fichberg <rfichberg@gmail.com>
app/models/reading.rb
1 class Reading < KalibroGem::Entities::Reading 1 class Reading < KalibroGem::Entities::Reading
2 include KalibroRecord 2 include KalibroRecord
3 3
  4 + validates :color, presence: true
  5 + validates :label, presence: true, kalibro_uniqueness: true
  6 +
4 end 7 end
spec/factories/readings.rb
@@ -15,11 +15,11 @@ @@ -15,11 +15,11 @@
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17 FactoryGirl.define do 17 FactoryGirl.define do
18 - factory :reading, class: KalibroGem::Entities::Reading do 18 + factory :reading do
19 id 42 19 id 42
20 label "Good" 20 label "Good"
21 - grade 10.5 21 + grade 10.5
22 color "33DD33" 22 color "33DD33"
23 group_id 31 23 group_id 31
24 end 24 end
25 -end  
26 \ No newline at end of file 25 \ No newline at end of file
  26 +end
spec/models/reading_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 describe Reading do 3 describe Reading do
4 - 4 + describe 'validations' do
  5 + subject {FactoryGirl.build(:reading)}
  6 +
  7 + context 'active model validations' do
  8 + before :each do
  9 + Reading.expects(:all).at_least_once.returns([])
  10 + end
  11 +
  12 + it { should validate_presence_of(:label) }
  13 + it { should validate_presence_of(:color) }
  14 + end
  15 +
  16 + context 'kalibro validations' do
  17 + before :each do
  18 + Reading.expects(:request).returns(42)
  19 + end
  20 +
  21 + it 'should validate uniqueness' do
  22 + KalibroUniquenessValidator.any_instance.expects(:validate_each).with(subject, :label, subject.label)
  23 + subject.save
  24 + end
  25 + end
  26 + end
5 end 27 end