From af2b20fb99ad311952f60e6b1b8f87ec76b63efe Mon Sep 17 00:00:00 2001 From: davidwessman Date: Tue, 31 Mar 2015 01:16:25 +0200 Subject: [PATCH 1/3] FixRentAbilities --- app/models/ability.rb | 2 +- app/views/rents/_form.html.erb | 10 +++++----- spec/features/rent_spec.rb | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 spec/features/rent_spec.rb diff --git a/app/models/ability.rb b/app/models/ability.rb index ce5a8cfb1..7750da6c6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -15,7 +15,7 @@ def initialize(user) # TODO Should be removed when everyone is required to log in. # /d.wessman 2015-03-28 can [:read, :update_worker, :remove_worker, :authorize], CafeWork - can [:read, :main], Rent + can [:read, :main, :new, :edit, :update, :create, :authorize], Rent # Abilities all signed in users get if user.id diff --git a/app/views/rents/_form.html.erb b/app/views/rents/_form.html.erb index 0f7aa03fd..7d11def68 100644 --- a/app/views/rents/_form.html.erb +++ b/app/views/rents/_form.html.erb @@ -29,8 +29,8 @@ <%= f.label 'E-post & telefon', class: 'reg-label' %>
-
<%= f.text_field :email, class: 'form-control', placeholder: "Epost" %>
-
<%= f.text_field :phone, class: 'form-control', placeholder: "Telefon" %>
+
<%= f.email_field :email, class: 'form-control', placeholder: "Epost" %>
+
<%= f.phone_field :phone, class: 'form-control', placeholder: "Telefon" %>
<% if current_user %> @@ -43,11 +43,11 @@ <%= f.label 'Från', class: 'reg-label' %>
- <%= f.datetime_select :d_from, minute_step: 10, class: 'form-control' %> + <%= f.text_field :d_from, class: 'datetimepicker' %>
<%= f.label 'Till', class: 'reg-label' %>
- <%= f.datetime_select :d_til, minute_step: 10, class: 'form-control' %> + <%= f.text_field :d_til, class: 'datetimepicker' %>
<% if (@rents)&&(@rents.count > 0) %> Bokningar (från idag + 30 dagar):
@@ -81,4 +81,4 @@ -<% end %> \ No newline at end of file +<% end %> diff --git a/spec/features/rent_spec.rb b/spec/features/rent_spec.rb new file mode 100644 index 000000000..95ed522d6 --- /dev/null +++ b/spec/features/rent_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' +feature 'tries to rent the car' do + let(:rent) { build(:rent) } + scenario 'they get alert with text "Loggade in"' do + visit '/bil/bokningar/ny' + find(:css, "#rent_disclaimer").set(true) + # TODO Include javascript-testing + #fill_in 'rent_name', with: rent.name + #fill_in 'rent_lastname', with: rent.lastname + #fill_in 'rent_email', with: rent.email + #fill_in 'rent_phone', with: rent.phone + #fill_in 'rent_purpose', with: rent.purpose + #fill_in 'rent_d_from', with: rent.d_from + #fill_in 'rent_d_til', with: rent.d_til + #click_button 'Spara' + #click_button 'Ok' + end +end From 45dde3dbf7c652e5c8c3c9f83d5429fc19206341 Mon Sep 17 00:00:00 2001 From: Erik Henriksson Date: Tue, 31 Mar 2015 09:36:01 +0200 Subject: [PATCH 2/3] Use poltergeist/PhantomJS for JS feature testing Conflicts: spec/spec_helper.rb --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d59613b08..08cee6505 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,6 +25,9 @@ require 'capybara/rspec' require 'capybara/rails' +require 'capybara/poltergeist' +Capybara.javascript_driver = :poltergeist + # I had to include this, /d.wessman 2015-03-20 require 'database_cleaner' # Devise helpers From 27b162b7e02135ccb428258a032f6f6f44a8f850 Mon Sep 17 00:00:00 2001 From: Erik Henriksson Date: Tue, 31 Mar 2015 11:00:50 +0200 Subject: [PATCH 3/3] Uncomment the test --- spec/features/rent_spec.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/features/rent_spec.rb b/spec/features/rent_spec.rb index 95ed522d6..2f6c823ee 100644 --- a/spec/features/rent_spec.rb +++ b/spec/features/rent_spec.rb @@ -1,18 +1,18 @@ require 'rails_helper' -feature 'tries to rent the car' do +feature 'tries to rent the car', js: true do let(:rent) { build(:rent) } scenario 'they get alert with text "Loggade in"' do visit '/bil/bokningar/ny' - find(:css, "#rent_disclaimer").set(true) - # TODO Include javascript-testing - #fill_in 'rent_name', with: rent.name - #fill_in 'rent_lastname', with: rent.lastname - #fill_in 'rent_email', with: rent.email - #fill_in 'rent_phone', with: rent.phone - #fill_in 'rent_purpose', with: rent.purpose - #fill_in 'rent_d_from', with: rent.d_from - #fill_in 'rent_d_til', with: rent.d_til - #click_button 'Spara' - #click_button 'Ok' + find(:css, '#rent_disclaimer').set(true) + fill_in 'rent_name', with: rent.name + fill_in 'rent_lastname', with: rent.lastname + fill_in 'rent_email', with: rent.email + fill_in 'rent_phone', with: rent.phone + fill_in 'rent_purpose', with: rent.purpose + # This does not work, we need to figure out how to set a date in the + # datepicker. Remember we can execute scripts by page.execute_script + fill_in 'rent_d_from', with: rent.d_from + fill_in 'rent_d_til', with: rent.d_til + click_button 'Spara' end end