diff --git a/Gemfile.lock b/Gemfile.lock index 5d744da38..70a252dc1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM csv_shaper (1.0.0) activesupport (>= 3.0.0) dalli (2.7.0) + database_cleaner (1.3.0) debug_inspector (0.0.2) debugger (1.6.6) columnize (>= 0.3.1) @@ -327,6 +328,7 @@ DEPENDENCIES coveralls csv_shaper dalli + database_cleaner (~> 1.3.0) debugger devise (~> 3.0.0) factory_girl_rails (~> 4.0) diff --git a/app/assets/javascripts/plantings.js.coffee b/app/assets/javascripts/plantings.js.coffee index 4d858f66b..96318c04e 100644 --- a/app/assets/javascripts/plantings.js.coffee +++ b/app/assets/javascripts/plantings.js.coffee @@ -17,6 +17,8 @@ jQuery -> el.val( ui.item.name ) $( '#planting_crop_id' ).val( ui.item.id ) false + change: ( event, ui ) -> + console.log( event, ui ) .data( 'uiAutocomplete' )._renderItem = ( ul, item ) -> $( '
' ) .data( 'item.autocomplete', item ) diff --git a/spec/features/planting_a_crop_spec.rb b/spec/features/planting_a_crop_spec.rb index 7f38a3eda..94e01c29a 100644 --- a/spec/features/planting_a_crop_spec.rb +++ b/spec/features/planting_a_crop_spec.rb @@ -11,17 +11,12 @@ feature "Planting a crop", :js => true do scenario "Typing in the crop name displays suggestions" do within "form#new_planting" do - # fill_autocomplete 'crop', with: 'm' - fill_in 'crop', :with => "m" - - binding.pry - - sleep 1000 - - page.execute_script %Q{ $('#crop').trigger('focus') } - page.execute_script %Q{ $('#crop').trigger('keydown') } - expect(page).to have_content("maize") + fill_autocomplete "crop", with: "m" end + + expect(page).to have_content("maize") + select_from_autocomplete("maize") + expect(page).to have_selector("input#planting_crop_id[value='#{maize.id}']", :visible => false) end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b2af2ab6e..4e9bf8273 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,7 +33,7 @@ RSpec.configure do |config| # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. - config.use_transactional_fixtures = true + config.use_transactional_fixtures = false # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 16d7abdec..97be826c1 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -3,14 +3,13 @@ module FeatureHelpers def fill_autocomplete(field, options = {}) fill_in field, :with => options[:with] - sleep 3 - page.execute_script %Q{ $('##{field}').trigger('focus') } page.execute_script %Q{ $('##{field}').trigger('keydown') } - # selector = %Q{ul.ui-autocomplete li.ui-menu-item a:contains("#{options[:select]}")} + end - # page.should have_selector('ul.ui-autocomplete li.ui-menu-item a') - # page.execute_script %Q{ $('#{selector}').trigger('mouseenter').click() } + def select_from_autocomplete(selection) + selector = %Q{ul.ui-autocomplete li.ui-menu-item a:contains("#{selection}")} + page.execute_script %Q{ $('#{selector}').trigger('mouseenter').click() } end