Commit 74346a0

mo khan <mo@mokhan.ca>
2016-05-03 04:34:41
implement feature spec to search by city
1 parent 5b35ca5
Changed files (5)
app
features
spec
support
app/views/layouts/application.html.erb
@@ -33,7 +33,7 @@
                 <ul class="right">
                   <% if feature_available?(:gym) %>
                   <li>
-                    <%= form_tag search_path, method: :get, remote: true do %>
+                    <%= form_tag search_path, id: "search-form", method: :get, remote: true do %>
                       <%= search_field_tag :q, params[:q], placeholder: t('.search') %>
                     <% end %>
                   </li>
features/step_definitions/gym_steps.rb
@@ -15,6 +15,8 @@ Then /^it lists all gyms$/ do
   end
 end
 
-When /^I choose a city$/ do
-  pending
+When /^they search for a city/ do
+  gym = @gyms.sample
+  @subject.search(gym.location.city)
+  @gyms = [gym]
 end
features/support/env.rb
@@ -6,6 +6,7 @@
 
 require 'cucumber/rails'
 
+$flipper.enable(:gym)
 # Capybara defaults to CSS3 selectors rather than XPath.
 # If you'd prefer to use XPath, just uncomment this line and adjust any
 # selectors in your step definitions to use the XPath syntax.
@@ -28,13 +29,7 @@ require 'cucumber/rails'
 #
 ActionController::Base.allow_rescue = false
 
-# Remove/comment out the lines below if your app doesn't have a database.
-# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
-begin
-  DatabaseCleaner.strategy = :transaction
-rescue NameError
-  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
-end
+DatabaseCleaner.strategy = :transaction
 
 # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
 # See the DatabaseCleaner documentation for details. Example:
features/finding_a_gym.feature
@@ -12,5 +12,5 @@ Feature: Finding a gym
     Given the user is logged in
     And There are 3 gyms
     When the user is on the gyms page
-    And I choose a city
+    And they search for a city
     Then it lists all gyms
spec/support/pages/gyms_page.rb
@@ -4,4 +4,11 @@ class GymsPage < PageModel
   def initialize
     super gyms_path
   end
+
+  def search(query)
+    within "#search-form" do
+      fill_in "q", with: query
+      page.execute_script("$('form#search-form').submit()")
+    end
+  end
 end