<%= form_for(@cabpool) do |c| %>
-
+ <%= render 'shared/error_messages_cabpool' %>
<%= c.label :number_of_people, "Number of people to travel with" %>
<%= c.text_field :number_of_people, class: 'form-control' %>
diff --git a/app/views/shared/_error_messages_cabpool.html.erb b/app/views/shared/_error_messages_cabpool.html.erb
new file mode 100644
index 0000000..f96d4ae
--- /dev/null
+++ b/app/views/shared/_error_messages_cabpool.html.erb
@@ -0,0 +1,17 @@
+<% if @cabpool.errors.any? %>
+
+
+ This form contains <%= pluralize(@cabpool.errors.count, "error") %>.
+
+
+ <% @cabpool.errors.full_messages.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+ <% unless @locality_errors.nil? %>
+ <% @locality_errors.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+ <% end %>
+
+
+<% end %>
\ No newline at end of file
diff --git a/spec/controllers/cabpools_controller_spec.rb b/spec/controllers/cabpools_controller_spec.rb
index 4f080b1..c2cb4ff 100644
--- a/spec/controllers/cabpools_controller_spec.rb
+++ b/spec/controllers/cabpools_controller_spec.rb
@@ -10,7 +10,6 @@
stub_locality = Locality.new(:name =>"Blah")
allow(Locality).to receive(:find).and_return(stub_locality)
allow(stub_locality).to receive(:name).and_return("Blah")
-
end
it 'should render create cabpools page' do
diff --git a/spec/factories/cabpools.rb b/spec/factories/cabpools.rb
index 7309886..24bff3b 100644
--- a/spec/factories/cabpools.rb
+++ b/spec/factories/cabpools.rb
@@ -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
diff --git a/spec/models/cabpool_spec.rb b/spec/models/cabpool_spec.rb
index 628949e..2546b31 100644
--- a/spec/models/cabpool_spec.rb
+++ b/spec/models/cabpool_spec.rb
@@ -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