-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Thejas | Nikhil] #2 Added a validation check for the Cabpool Model
- Loading branch information
thejasbabu
committed
Dec 1, 2015
1 parent
1a175b4
commit b0ca479
Showing
7 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
class Cabpool < ActiveRecord::Base | ||
|
||
has_many :users | ||
belongs_to :locality | ||
|
||
validates_presence_of :number_of_people, :timein, :timeout, :route | ||
validates_numericality_of :number_of_people, less_than_or_equal_to: 4, greater_than_or_equal_to: 1 | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<% if @cabpool.errors.any? %> | ||
<div id="error_explanation"> | ||
<div class="alert alert-danger"> | ||
This form contains <%= pluralize(@cabpool.errors.count, "error") %>. | ||
</div> | ||
<ul> | ||
<% @cabpool.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
<% unless @locality_errors.nil? %> | ||
<% @locality_errors.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
FactoryGirl.define do | ||
factory :cabpools do | ||
factory :cabpool do | ||
route "MyString" | ||
number_of_people 1 | ||
timein "MyString" | ||
timeout "MyString" | ||
locality nil | ||
number_of_people 1 | ||
timein "MyString" | ||
timeout "MyString" | ||
locality nil | ||
end | ||
|
||
trait :without_number_of_people do | ||
number_of_people nil | ||
end | ||
|
||
trait :without_time_in do | ||
timein '' | ||
end | ||
|
||
trait :without_time_out do | ||
timeout '' | ||
end | ||
|
||
trait :without_routes do | ||
route '' | ||
end | ||
|
||
trait :without_less_than_four_people do | ||
number_of_people 6 | ||
end | ||
|
||
trait :without_greater_than_one_person do | ||
number_of_people 0 | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Cabpool, type: :model do | ||
|
||
it 'Number of people should not be empty' do | ||
cabpool = build(:cabpool, :without_number_of_people) | ||
expect(cabpool.valid?).to be false | ||
end | ||
|
||
it 'Time in of the cabpool should not be empty' do | ||
cabpool = build(:cabpool, :without_time_in) | ||
expect(cabpool.valid?).to be false | ||
end | ||
|
||
it 'Time out of the cabpool should not be empty' do | ||
cabpool = build(:cabpool, :without_time_out) | ||
expect(cabpool.valid?).to be false | ||
end | ||
|
||
it 'Routes of the cabpool should not be empty' do | ||
cabpool = build(:cabpool, :without_routes) | ||
expect(cabpool.valid?).to be false | ||
end | ||
|
||
it 'Number of people should be less than or equal to 4' do | ||
cabpool = build(:cabpool, :without_less_than_four_people) | ||
expect(cabpool.valid?).to be false | ||
end | ||
|
||
it 'Number of people should be greater than or equal to 1' do | ||
cabpool = build(:cabpool, :without_greater_than_one_person) | ||
expect(cabpool.valid?).to be false | ||
end | ||
end |