From e54a48e732a606ee13d59179ba4abe996d14e2e8 Mon Sep 17 00:00:00 2001 From: Artur-Gaifutdinov Date: Wed, 26 Feb 2014 20:56:40 -0500 Subject: [PATCH 1/3] Increase tests coverage --- Gemfile | 1 + Gemfile.lock | 8 ++++++++ app/controllers/answers_controller.rb | 2 -- app/controllers/static_controller.rb | 11 +++++------ features/answers.feature | 7 +++++-- features/blog.feature | 5 ++++- features/lessons.feature | 13 +++++++++++++ features/moderator.feature | 3 ++- features/programs.feature | 3 +++ features/questions.feature | 3 +++ features/signup.feature | 3 +++ features/statics.feature | 19 +++++++++++++++++++ features/step_definitions/lesson_steps.rb | 17 +++++++++++++++++ features/step_definitions/static_steps.rb | 8 ++++++++ features/support/env.rb | 1 + features/users.feature | 5 +++-- 16 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 features/lessons.feature create mode 100644 features/statics.feature create mode 100644 features/step_definitions/lesson_steps.rb create mode 100644 features/step_definitions/static_steps.rb diff --git a/Gemfile b/Gemfile index 4bf72113..0e9edb9f 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,7 @@ group :development do end group :development, :test do + gem 'debugger' gem 'fabrication' gem 'rspec-rails' gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 3d8a7b9f..43869d85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,7 @@ GEM coffee-script-source execjs coffee-script-source (1.7.0) + columnize (0.3.6) coveralls (0.7.0) multi_json (~> 1.3) rest-client @@ -82,6 +83,12 @@ GEM nokogiri (>= 1.5.0) rails (>= 3.0.0) database_cleaner (1.2.0) + debugger (1.6.5) + columnize (>= 0.3.1) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.3.1) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.3.2) devise (2.2.8) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -249,6 +256,7 @@ DEPENDENCIES coveralls cucumber-rails database_cleaner + debugger devise (~> 2.2.2) fabrication faker diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index e9377081..0761042d 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -19,7 +19,5 @@ def update format.html { redirect_to question_url(resource.question) } end end - - end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index e34ded3e..843fd4d1 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -23,7 +23,10 @@ def download @other_platforms = ["mac", "windows", "linux"] - [@platform] end - def api_root; render :layout => "api"; end + def api_root + render :layout => "api" + end + def newest_version render :json => {:version => "1.0.0"} end @@ -31,10 +34,6 @@ def newest_version protected def platform - if Rails.env.test? - "mac" - else - request.user_agent.match(/Mac|Linux|Windows/).try(:[], 0).try(:downcase) - end + request.user_agent.downcase end end diff --git a/features/answers.feature b/features/answers.feature index 600859ff..7a51357b 100644 --- a/features/answers.feature +++ b/features/answers.feature @@ -1,9 +1,12 @@ Feature: CRUD actions for answers As a user of the site, I can perform standard CRUD actions on answers + + Background: + Given "Mac" user agent Scenario: Create an answer - Given a question exists + And a question exists And I answer that question Then I should be notified that my answer was submitted And an email should be sent to the author @@ -11,7 +14,7 @@ Feature: CRUD actions for answers And my answer should show on my profile page Scenario: Edit an answer - Given a question exists + And a question exists And I answer that question When I edit that answer Then I should see the updated answer diff --git a/features/blog.feature b/features/blog.feature index 4c538602..9b342586 100644 --- a/features/blog.feature +++ b/features/blog.feature @@ -1,7 +1,10 @@ Feature: Hackety Blog As an admin, I can post to the hackety blog. - + + Background: + Given "Mac" user agent + Scenario: Read the blog Given a blog post exists When I visit the blog diff --git a/features/lessons.feature b/features/lessons.feature new file mode 100644 index 00000000..0f3b92ad --- /dev/null +++ b/features/lessons.feature @@ -0,0 +1,13 @@ +Feature: Hackety Lessons + + As a user of the site, I can visit lessons page + + Scenario: View the lessons + When I visit lessons path + Then I should see the list of lessons + + Scenario: View specific lesson + When I visit lessons path + When I click on lesson's title + Then I should see lesson content + diff --git a/features/moderator.feature b/features/moderator.feature index 2071f212..1560c2cf 100644 --- a/features/moderator.feature +++ b/features/moderator.feature @@ -3,7 +3,8 @@ Feature: Moderate questions As a moderator, I should be able to delete questions from the site. Background: - Given there is a question from someone else + Given "Mac" user agent + And there is a question from someone else Scenario: Delete a question Given I am a moderator diff --git a/features/programs.feature b/features/programs.feature index 5680b723..1f1d1380 100644 --- a/features/programs.feature +++ b/features/programs.feature @@ -1,6 +1,9 @@ Feature: Access Programs As a user of the site, I want to access users' programs + + Background: + Given "Mac" user agent Scenario: View a featured program Given there is a featured program diff --git a/features/questions.feature b/features/questions.feature index ac233e90..0a04f461 100644 --- a/features/questions.feature +++ b/features/questions.feature @@ -2,6 +2,9 @@ Feature: CRUD actions for question As a user of the site, I can perform standard CRUD actions on questions + Background: + Given "Mac" user agent + Scenario: Create a question When I create a new question Then I should be told the question was created diff --git a/features/signup.feature b/features/signup.feature index f1123432..5a386009 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -1,6 +1,9 @@ Feature: Sign up for an account As a new Hackety user, I want to create a new account and log in with it + + Background: + Given "Mac" user agent Scenario: Create an account via the signup form When I register a new account diff --git a/features/statics.feature b/features/statics.feature new file mode 100644 index 00000000..37294c25 --- /dev/null +++ b/features/statics.feature @@ -0,0 +1,19 @@ +Feature: Detect user's platform and provide download link + + As a fresh Hackety user, I want to download software for my current OS + + Scenario: MacOS User + Given "Mac" user agent + Then I should be able to download "mac" software + + Scenario: Windows User + Given "Windows" user agent + Then I should be able to download "windows" software + + Scenario: Linux User + Given "Linux" user agent + Then I should be able to download "linux" software + + Scenario: Android User + Given "android" user agent + Then I should be able to download "android" software diff --git a/features/step_definitions/lesson_steps.rb b/features/step_definitions/lesson_steps.rb new file mode 100644 index 00000000..d7355def --- /dev/null +++ b/features/step_definitions/lesson_steps.rb @@ -0,0 +1,17 @@ +When(/^I visit lessons path$/) do + visit lessons_path +end + +Then(/^I should see the list of lessons$/) do + page.should have_content("Lessons") + page.should have_content("A Tour of Hackety Hack") +end + +When(/^I click on lesson's title$/) do + click_link("A Tour of Hackety Hack") +end + +Then(/^I should see lesson content$/) do + expect(page).to have_title "A Tour of Hackety Hack" + page.should have_content("Welcome to the Hackety Hack tour!") +end diff --git a/features/step_definitions/static_steps.rb b/features/step_definitions/static_steps.rb new file mode 100644 index 00000000..b09a519a --- /dev/null +++ b/features/step_definitions/static_steps.rb @@ -0,0 +1,8 @@ +Given(/^"(.*?)" user agent$/) do |agent| + page.driver.header('User-Agent', agent) +end + +Then(/^I should be able to download "(.*?)" software$/) do |system| + visit download_path + page.should have_content("Version 1.0.1 for #{system}") +end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index ee6880e7..25e027c5 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -8,6 +8,7 @@ require_relative '../../spec/code_coverage' require 'cucumber/rails' +require 'ruby-debug' # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In # order to ease the transition to Capybara we set the default here. If you'd diff --git a/features/users.feature b/features/users.feature index 7dca8ff5..52ecaa78 100644 --- a/features/users.feature +++ b/features/users.feature @@ -2,8 +2,9 @@ Feature: Manage account As a user of this site, I can view and update my profile, see my followers - Background: The user is logged in - Given a logged in user + Background: + Given "Mac" user agent + And a logged in user Scenario: View my profile When I go to look at my profile page From 2cebc66b2bde36320b8e2eeec474a45ad4e6ba4d Mon Sep 17 00:00:00 2001 From: Artur-Gaifutdinov Date: Thu, 27 Feb 2014 10:58:56 -0500 Subject: [PATCH 2/3] User-Agent refactoring --- features/answers.feature | 3 --- features/blog.feature | 5 +---- features/moderator.feature | 3 +-- features/programs.feature | 3 --- features/questions.feature | 3 --- features/signup.feature | 3 --- features/support/env.rb | 1 + features/users.feature | 3 +-- 8 files changed, 4 insertions(+), 20 deletions(-) diff --git a/features/answers.feature b/features/answers.feature index 7a51357b..d647cebe 100644 --- a/features/answers.feature +++ b/features/answers.feature @@ -2,9 +2,6 @@ Feature: CRUD actions for answers As a user of the site, I can perform standard CRUD actions on answers - Background: - Given "Mac" user agent - Scenario: Create an answer And a question exists And I answer that question diff --git a/features/blog.feature b/features/blog.feature index 9b342586..4c538602 100644 --- a/features/blog.feature +++ b/features/blog.feature @@ -1,10 +1,7 @@ Feature: Hackety Blog As an admin, I can post to the hackety blog. - - Background: - Given "Mac" user agent - + Scenario: Read the blog Given a blog post exists When I visit the blog diff --git a/features/moderator.feature b/features/moderator.feature index 1560c2cf..2071f212 100644 --- a/features/moderator.feature +++ b/features/moderator.feature @@ -3,8 +3,7 @@ Feature: Moderate questions As a moderator, I should be able to delete questions from the site. Background: - Given "Mac" user agent - And there is a question from someone else + Given there is a question from someone else Scenario: Delete a question Given I am a moderator diff --git a/features/programs.feature b/features/programs.feature index 1f1d1380..f2ead8ec 100644 --- a/features/programs.feature +++ b/features/programs.feature @@ -2,9 +2,6 @@ Feature: Access Programs As a user of the site, I want to access users' programs - Background: - Given "Mac" user agent - Scenario: View a featured program Given there is a featured program Then I should be able to view a highlighted program diff --git a/features/questions.feature b/features/questions.feature index 0a04f461..ac233e90 100644 --- a/features/questions.feature +++ b/features/questions.feature @@ -2,9 +2,6 @@ Feature: CRUD actions for question As a user of the site, I can perform standard CRUD actions on questions - Background: - Given "Mac" user agent - Scenario: Create a question When I create a new question Then I should be told the question was created diff --git a/features/signup.feature b/features/signup.feature index 5a386009..442dd0bd 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -2,9 +2,6 @@ Feature: Sign up for an account As a new Hackety user, I want to create a new account and log in with it - Background: - Given "Mac" user agent - Scenario: Create an account via the signup form When I register a new account Then I should be logged in with my new account diff --git a/features/support/env.rb b/features/support/env.rb index 25e027c5..e3e7bc48 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -40,6 +40,7 @@ Before do DatabaseCleaner[:mongo_mapper].clean + page.driver.header('User-Agent', "Mac") end # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. diff --git a/features/users.feature b/features/users.feature index 52ecaa78..cbe60fdc 100644 --- a/features/users.feature +++ b/features/users.feature @@ -3,8 +3,7 @@ Feature: Manage account As a user of this site, I can view and update my profile, see my followers Background: - Given "Mac" user agent - And a logged in user + Given a logged in user Scenario: View my profile When I go to look at my profile page From 114bc6280167b60c6010ddc4a35c5ee00997a27f Mon Sep 17 00:00:00 2001 From: Artur-Gaifutdinov Date: Thu, 27 Feb 2014 12:40:20 -0500 Subject: [PATCH 3/3] Nil platform handler for StaticControllers --- app/controllers/static_controller.rb | 2 +- features/support/env.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 843fd4d1..60acc47c 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -34,6 +34,6 @@ def newest_version protected def platform - request.user_agent.downcase + request.user_agent.nil? ? nil : request.user_agent.downcase end end diff --git a/features/support/env.rb b/features/support/env.rb index e3e7bc48..25e027c5 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -40,7 +40,6 @@ Before do DatabaseCleaner[:mongo_mapper].clean - page.driver.header('User-Agent', "Mac") end # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.