diff --git a/Gemfile.lock b/Gemfile.lock index da8b141..dd53fb1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,61 +1,95 @@ GEM remote: https://rubygems.org/ specs: - builder (3.2.2) - capybara (2.4.4) - mime-types (>= 1.16) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + backports (3.11.1) + builder (3.2.3) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - xpath (~> 2.0) - coderay (1.1.0) - cucumber (1.3.17) + xpath (>= 2.0, < 4.0) + coderay (1.1.2) + cucumber (3.1.0) builder (>= 2.1.2) - diff-lcs (>= 1.1.3) - gherkin (~> 2.12) + cucumber-core (~> 3.1.0) + cucumber-expressions (~> 5.0.4) + cucumber-wire (~> 0.0.1) + diff-lcs (~> 1.3) + gherkin (~> 5.0) multi_json (>= 1.7.5, < 2.0) - multi_test (>= 0.1.1) + multi_test (>= 0.1.2) + cucumber-core (3.1.0) + backports (>= 3.8.0) + cucumber-tag_expressions (~> 1.1.0) + gherkin (>= 5.0.0) + cucumber-expressions (5.0.13) cucumber-sinatra (0.5.0) templater (>= 1.0.0) - diff-lcs (1.2.5) + cucumber-tag_expressions (1.1.1) + cucumber-wire (0.0.1) + diff-lcs (1.3) extlib (0.9.16) - gherkin (2.12.2) - multi_json (~> 1.3) - haml (4.0.6) + ffi (1.9.21) + gherkin (5.0.0) + haml (5.0.4) + temple (>= 0.8.0) tilt - highline (1.6.21) - method_source (0.8.2) - mime-types (2.4.3) - mini_portile (0.6.1) - multi_json (1.10.1) - multi_test (0.1.1) - nokogiri (1.6.4.1) - mini_portile (~> 0.6.0) - pry (0.10.1) + highline (1.7.10) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + multi_json (1.13.1) + multi_test (0.1.2) + mustermann (1.0.2) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + pry (0.11.3) coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rack (1.5.2) - rack-protection (1.5.3) + method_source (~> 0.9.0) + public_suffix (3.0.2) + rack (2.0.4) + rack-protection (2.0.1) rack - rack-test (0.6.2) - rack (>= 1.0) - rspec-expectations (3.1.2) + rack-test (0.8.2) + rack (>= 1.0, < 3) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-support (3.1.2) - sinatra (1.4.5) - rack (~> 1.4) - rack-protection (~> 1.4) - tilt (~> 1.3, >= 1.3.4) - slop (3.6.0) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-support (3.7.1) + sass (3.5.5) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sinatra (2.0.1) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.1) + tilt (~> 2.0) templater (1.0.0) diff-lcs (>= 1.1.2) extlib (>= 0.9.5) highline (>= 1.4.0) - tilt (1.4.1) - xpath (2.0.0) - nokogiri (~> 1.3) + temple (0.8.0) + tilt (2.0.8) + xpath (3.0.0) + nokogiri (~> 1.8) PLATFORMS ruby @@ -66,5 +100,10 @@ DEPENDENCIES cucumber-sinatra haml pry + rspec rspec-expectations + sass sinatra + +BUNDLED WITH + 1.16.1 diff --git a/app.rb b/app.rb index 670284d..fb3cbc7 100644 --- a/app.rb +++ b/app.rb @@ -31,7 +31,17 @@ def logged_in? end get "/dashboard" do - @username = session[:user] - haml :dashboard + #@username = session[:user] + #haml :dashboard + #first check if user is authenticated or not + if logged_in? + @username = session[:user] + haml :dashboard + else + @message = 'Unauthorized access!' + #redirect to home page + haml :index + end + end end diff --git a/features/.DS_Store b/features/.DS_Store new file mode 100644 index 0000000..b2a02ab Binary files /dev/null and b/features/.DS_Store differ diff --git a/features/login.feature b/features/login.feature index 3fff7cf..d08cf68 100644 --- a/features/login.feature +++ b/features/login.feature @@ -5,6 +5,5 @@ Feature: Login Page Scenario: Authenticated User Given the login page - When I log in with proper credentials - Then I should see the secret page - + When I log in with username and password as "admin" + Then I should see the secret page with my my username "admin" diff --git a/features/logout.feature b/features/logout.feature index 251c445..e3bc2aa 100644 --- a/features/logout.feature +++ b/features/logout.feature @@ -1 +1,8 @@ -#Add your codez here +Feature: Logout functionality + When I want to end my session + I should be able to logout + +Scenario: User logs out + Given user secret page with credentials "admin" + When I click on "Logout" + Then I should be redirected to logout page with a message "You have been logged out" diff --git a/features/step_definitions/login_steps.rb b/features/step_definitions/login_steps.rb index 61f803a..17d6906 100644 --- a/features/step_definitions/login_steps.rb +++ b/features/step_definitions/login_steps.rb @@ -1,14 +1,13 @@ Given(/^the login page$/) do - #put your code here - pending + visit('http://localhost:4567') end -When(/^I log in with proper credentials$/) do - #put your code here - pending +When(/^I log in with username and password as "(.*?)"$/) do |credential| + fill_in 'username', :with => credential + fill_in 'password', :with => credential + click_button 'Login' end -Then(/^I should see the secret page$/) do - #put your code here - pending +Then(/^I should see the secret page with my my username "(.*?)"$/) do |username| + expect(page).to have_content username end diff --git a/features/step_definitions/logout_steps.rb b/features/step_definitions/logout_steps.rb index 251c445..5a4ed03 100644 --- a/features/step_definitions/logout_steps.rb +++ b/features/step_definitions/logout_steps.rb @@ -1 +1,15 @@ -#Add your codez here +Given (/^user secret page with credentials "(.*?)"$/) do |credentails| + steps %{ + Given the login page + When I log in with username and password as "#{credentails}" + Then I should see the secret page with my my username "#{credentails}" + } +end + +When (/^I click on "(.*?)"$/) do |link| + click_link link +end + +Then(/^I should be redirected to logout page with a message "(.*?)"$/) do |message| + expect(page).to have_content message +end