Commit 6e10cd8a8e73f4241152b3d61518d3d61fd50d45
Committed by
Rafael Manzo
1 parent
b42c9613
Exists in
colab
and in
4 other branches
Reading model.
Signed-off-by: Renan Fichberg <rfichberg@gmail.com>
Showing
3 changed files
with
29 additions
and
4 deletions
Show diff stats
app/models/reading.rb
spec/factories/readings.rb
| ... | ... | @@ -15,11 +15,11 @@ |
| 15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | 16 | |
| 17 | 17 | FactoryGirl.define do |
| 18 | - factory :reading, class: KalibroGem::Entities::Reading do | |
| 18 | + factory :reading do | |
| 19 | 19 | id 42 |
| 20 | 20 | label "Good" |
| 21 | - grade 10.5 | |
| 21 | + grade 10.5 | |
| 22 | 22 | color "33DD33" |
| 23 | 23 | group_id 31 |
| 24 | 24 | end |
| 25 | -end | |
| 26 | 25 | \ No newline at end of file |
| 26 | +end | ... | ... |
spec/models/reading_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 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 | 27 | end | ... | ... |