]> git.openstreetmap.org Git - rails.git/commitdiff
Add a basic feature test for reporting diary entries.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 6 Sep 2017 10:24:54 +0000 (11:24 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 6 Sep 2017 10:26:32 +0000 (11:26 +0100)
config/routes.rb
test/features/can_access_home_test.rb [new file with mode: 0644]
test/features/report_diary_entry_test.rb [new file with mode: 0644]
test/test_helper.rb

index c92926bd5fc46d20cc6d0e94f4e2b74690d82c60..2fec73c4e7dbc66c1dedae25764646531f89781b 100644 (file)
@@ -223,7 +223,7 @@ OpenStreetMap::Application.routes.draw do
   match "/user/:display_name/diary" => "diary_entry#list", :via => :get
   match "/diary/:language" => "diary_entry#list", :via => :get
   match "/diary" => "diary_entry#list", :via => :get
-  match "/user/:display_name/diary/:id" => "diary_entry#view", :via => :get, :id => /\d+/
+  match "/user/:display_name/diary/:id" => "diary_entry#view", :via => :get, :id => /\d+/, :as => :diary_entry
   match "/user/:display_name/diary/:id/newcomment" => "diary_entry#comment", :via => :post, :id => /\d+/
   match "/user/:display_name/diary/:id/edit" => "diary_entry#edit", :via => [:get, :post], :id => /\d+/
   match "/user/:display_name/diary/:id/hide" => "diary_entry#hide", :via => :post, :id => /\d+/, :as => :hide_diary_entry
diff --git a/test/features/can_access_home_test.rb b/test/features/can_access_home_test.rb
new file mode 100644 (file)
index 0000000..396ffc9
--- /dev/null
@@ -0,0 +1,12 @@
+require "test_helper"
+
+class CanAccessHomeTest < Capybara::Rails::TestCase
+  def setup
+    stub_hostip_requests
+  end
+
+  def test_it_works
+    visit root_path
+    assert page.has_content? "BOpenStreetMap"
+  end
+end
diff --git a/test/features/report_diary_entry_test.rb b/test/features/report_diary_entry_test.rb
new file mode 100644 (file)
index 0000000..aaa89ad
--- /dev/null
@@ -0,0 +1,24 @@
+require "test_helper"
+
+class ReportDiaryEntryTest < Capybara::Rails::TestCase
+  def setup
+    create(:language, :code => "en")
+    @diary_entry = create(:diary_entry)
+  end
+
+  def test_it_works
+    sign_in_as(create(:user))
+    visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
+    assert page.has_content? @diary_entry.title
+
+    click_on "\u2690"
+    assert page.has_content? "Report"
+    assert page.has_content? I18n.t("issues.new.disclaimer.intro")
+
+    choose "report_type__SPAM" # FIXME: use label text when the radio button labels are working
+    fill_in "report_details", :with => "This is advertising"
+    click_on "Save changes"
+
+    assert page.has_content? "Your report has been registered sucessfully"
+  end
+end
index d41a369f88ebb3eaf6f5d0d1cfc3fabc1a967800..0e06c3c9ef8bb8c1246051745656c0528aa81edf 100644 (file)
@@ -5,6 +5,7 @@ ENV["RAILS_ENV"] = "test"
 require File.expand_path("../../config/environment", __FILE__)
 require "rails/test_help"
 require "webmock/minitest"
+require "minitest/rails/capybara"
 
 module ActiveSupport
   class TestCase
@@ -150,5 +151,13 @@ module ActiveSupport
         end
       end
     end
+
+    def sign_in_as(user)
+      stub_hostip_requests
+      visit login_path
+      fill_in "username", :with => user.email
+      fill_in "password", :with => "test"
+      click_on "Login", :match => :first
+    end
   end
 end