From fa8f2f2917be3ce5209aadc015e425c1aafb84e8 Mon Sep 17 00:00:00 2001 From: Sarah Port Date: Thu, 8 Feb 2018 09:36:46 -0800 Subject: [PATCH 01/11] set up basic admin page controller/view --- app/controllers/admin/admin_controller.rb | 22 +++++++++++++++++++ app/controllers/admin/sessions_controller.rb | 4 ---- .../get_fb_event_object_from_fb_id_service.rb | 9 ++++++++ app/views/admin/admin/index.html.erb | 3 +++ config/routes.rb | 2 +- .../admin/admin_controller_spec.rb | 5 +++++ ...fb_event_object_from_fb_id_service_spec.rb | 6 +++++ 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 app/controllers/admin/admin_controller.rb create mode 100644 app/services/get_fb_event_object_from_fb_id_service.rb create mode 100644 app/views/admin/admin/index.html.erb create mode 100644 spec/controllers/admin/admin_controller_spec.rb create mode 100644 spec/services/get_fb_event_object_from_fb_id_service_spec.rb diff --git a/app/controllers/admin/admin_controller.rb b/app/controllers/admin/admin_controller.rb new file mode 100644 index 0000000..663593c --- /dev/null +++ b/app/controllers/admin/admin_controller.rb @@ -0,0 +1,22 @@ +class Admin::AdminController < ApplicationController + before_action :require_admin_login, only: :index + + def index + @user = User.find(current_user).email + + @events = [ + { + id: 1, + fb_id: '4f3817489', + created_at: Time.now, + updated_at: Time.now, + }, + { + id: 2, + fb_id: 'fajsdklfas', + created_at: 1.day.ago, + updated_at: 1.day.ago, + } + ] + end +end diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index b09f2a8..f49fa2b 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -4,10 +4,6 @@ class Admin::SessionsController < ApplicationController def new; end - def index - render plain: "Hello World!" - end - def create user = User.find_by(email: params[:email]) diff --git a/app/services/get_fb_event_object_from_fb_id_service.rb b/app/services/get_fb_event_object_from_fb_id_service.rb new file mode 100644 index 0000000..756d40e --- /dev/null +++ b/app/services/get_fb_event_object_from_fb_id_service.rb @@ -0,0 +1,9 @@ +class GetFbEventObjectFromFbIdService + def initialize(params) + @fb_id = params[:fb_id] + end + + def fetch + @fb_id + end +end \ No newline at end of file diff --git a/app/views/admin/admin/index.html.erb b/app/views/admin/admin/index.html.erb new file mode 100644 index 0000000..ebcc21c --- /dev/null +++ b/app/views/admin/admin/index.html.erb @@ -0,0 +1,3 @@ +Logged in as <%= @user %> + +<%= @events %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4d8c7df..aff2500 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ root 'welcome#index' namespace :admin do - get '/', to: 'sessions#index' + get '/', to: 'admin#index' get 'login', to: 'sessions#new' post 'login', to: 'sessions#create' end diff --git a/spec/controllers/admin/admin_controller_spec.rb b/spec/controllers/admin/admin_controller_spec.rb new file mode 100644 index 0000000..121b60d --- /dev/null +++ b/spec/controllers/admin/admin_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Admin::AdminController, type: :controller do + +end diff --git a/spec/services/get_fb_event_object_from_fb_id_service_spec.rb b/spec/services/get_fb_event_object_from_fb_id_service_spec.rb new file mode 100644 index 0000000..dbe926e --- /dev/null +++ b/spec/services/get_fb_event_object_from_fb_id_service_spec.rb @@ -0,0 +1,6 @@ +describe GetFbEventObjectFromFbIdService do + context ".fetch" do + it "returns a facebook event" do + end + end +end \ No newline at end of file From 2be2156ef120e0fdcf6b5325e8912918ce148cd4 Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 21 Mar 2018 20:48:25 -0700 Subject: [PATCH 02/11] Start implementation of admin page; general formatting for html files. --- app/assets/stylesheets/admin.scss | 3 +++ app/assets/stylesheets/application.scss | 3 ++- app/controllers/admin/admin_controller.rb | 2 +- app/views/admin/admin/index.html.erb | 12 ++++++--- app/views/layouts/_navbar.html.erb | 30 +++++++++++------------ app/views/layouts/application.html.erb | 7 +++++- 6 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 app/assets/stylesheets/admin.scss diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss new file mode 100644 index 0000000..1c513bb --- /dev/null +++ b/app/assets/stylesheets/admin.scss @@ -0,0 +1,3 @@ +#admin-page { + margin-top: 10px; +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index b7ab955..256e443 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -17,7 +17,8 @@ @import "bootstrap"; @import "font-awesome-sprockets"; @import "font-awesome"; - @import "submit_events"; + @import "submit_events"; + @import "admin"; .stats{ diff --git a/app/controllers/admin/admin_controller.rb b/app/controllers/admin/admin_controller.rb index 663593c..ddd97a3 100644 --- a/app/controllers/admin/admin_controller.rb +++ b/app/controllers/admin/admin_controller.rb @@ -2,7 +2,7 @@ class Admin::AdminController < ApplicationController before_action :require_admin_login, only: :index def index - @user = User.find(current_user).email + @user = User.find(current_user) @events = [ { diff --git a/app/views/admin/admin/index.html.erb b/app/views/admin/admin/index.html.erb index ebcc21c..b20a973 100644 --- a/app/views/admin/admin/index.html.erb +++ b/app/views/admin/admin/index.html.erb @@ -1,3 +1,9 @@ -Logged in as <%= @user %> - -<%= @events %> \ No newline at end of file +
+
+ <%= "Logged in as #{@user.email}." %> + <%= link_to('Log Out', '#') %> +
+
+ +
+
\ No newline at end of file diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 3c2bbd4..50659ce 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -1,17 +1,17 @@ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f02906c..c9d2eeb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,10 +6,15 @@ <%= stylesheet_link_tag "https://fonts.googleapis.com/css?family=Oswald" %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= render 'layouts/navbar' %> - <%= yield %> +
+
+ <%= yield %> +
+
From daf1ed10f99294288466791c93f223f4b525a66f Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 28 Mar 2018 19:44:41 -0700 Subject: [PATCH 03/11] Remove bootstrap-sass and use bootstrap 4 instead of 3. --- Gemfile | 1 - Gemfile.lock | 4 ---- app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index a43cf07..bd9f2f0 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,6 @@ gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.7' # Use SCSS for stylesheets -gem 'bootstrap-sass', '~> 3.3.6' gem 'sass-rails', '~> 5.0' gem 'font-awesome-sass', '~> 4.7.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index 000f223..580029c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,9 +49,6 @@ GEM autoprefixer-rails (>= 6.0.3) popper_js (>= 1.12.3, < 2) sass (>= 3.5.2) - bootstrap-sass (3.3.7) - autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) builder (3.2.3) byebug (9.1.0) capybara (2.15.4) @@ -229,7 +226,6 @@ PLATFORMS DEPENDENCIES bcrypt (~> 3.1.7) bootstrap - bootstrap-sass (~> 3.3.6) byebug capybara (~> 2.13) coffee-rails (~> 4.2) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index de35dc8..b686502 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,6 +14,7 @@ //= require jquery_ujs //= require turbolinks //= require jquery +//= require popper //= require bootstrap-sprockets //= require_tree . diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 256e443..82459c0 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,7 +13,6 @@ */ // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables" - @import "bootstrap-sprockets"; @import "bootstrap"; @import "font-awesome-sprockets"; @import "font-awesome"; From 15cee9f605e316064456677dc01d5a8191bdc2d5 Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 28 Mar 2018 19:47:05 -0700 Subject: [PATCH 04/11] Rename admin controller under admin namespace. --- app/controllers/admin/admin_controller.rb | 2 +- app/views/admin/admin/index.html.erb | 9 --------- config/routes.rb | 2 +- spec/controllers/admin/admin_controller_spec.rb | 5 ----- spec/controllers/admin/dashboard_controller_spec.rb | 5 +++++ 5 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 app/views/admin/admin/index.html.erb delete mode 100644 spec/controllers/admin/admin_controller_spec.rb create mode 100644 spec/controllers/admin/dashboard_controller_spec.rb diff --git a/app/controllers/admin/admin_controller.rb b/app/controllers/admin/admin_controller.rb index ddd97a3..6c59433 100644 --- a/app/controllers/admin/admin_controller.rb +++ b/app/controllers/admin/admin_controller.rb @@ -1,4 +1,4 @@ -class Admin::AdminController < ApplicationController +class Admin::DashBoardController < ApplicationController before_action :require_admin_login, only: :index def index diff --git a/app/views/admin/admin/index.html.erb b/app/views/admin/admin/index.html.erb deleted file mode 100644 index b20a973..0000000 --- a/app/views/admin/admin/index.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
-
- <%= "Logged in as #{@user.email}." %> - <%= link_to('Log Out', '#') %> -
-
- -
-
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index aff2500..4e85eb3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ root 'welcome#index' namespace :admin do - get '/', to: 'admin#index' + get '/', to: 'dashboard#index' get 'login', to: 'sessions#new' post 'login', to: 'sessions#create' end diff --git a/spec/controllers/admin/admin_controller_spec.rb b/spec/controllers/admin/admin_controller_spec.rb deleted file mode 100644 index 121b60d..0000000 --- a/spec/controllers/admin/admin_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Admin::AdminController, type: :controller do - -end diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb new file mode 100644 index 0000000..95cd2bd --- /dev/null +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Admin::DashBoardController, type: :controller do + +end From 4528469ad86ca6b554fa29356dd404586c1fcb7c Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 28 Mar 2018 19:47:46 -0700 Subject: [PATCH 05/11] Set up scaffold for admin dashboard page. --- app/views/admin/dashboard/index.html.erb | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/views/admin/dashboard/index.html.erb diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb new file mode 100644 index 0000000..768b58d --- /dev/null +++ b/app/views/admin/dashboard/index.html.erb @@ -0,0 +1,34 @@ +
+
+
+
+ <%= "Logged in as #{@user.email}." %> + <%= link_to('Log Out', '#') %> +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ <% @events.each do |event| %> +
+
+
+ + ... +
+
+
+ <% end %> +
+
\ No newline at end of file From e75c10ea6ecba251c731accef43ed5762d57bd57 Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 28 Mar 2018 20:55:54 -0700 Subject: [PATCH 06/11] Rename admin controller to dashboard. Update admin dashboard with finely-grained structure. --- app/assets/stylesheets/admin.scss | 2 + ..._controller.rb => dashboard_controller.rb} | 2 +- app/views/admin/dashboard/index.html.erb | 43 +++++++++++-------- app/views/layouts/application.html.erb | 4 +- .../admin/dashboard_controller_spec.rb | 2 +- 5 files changed, 31 insertions(+), 22 deletions(-) rename app/controllers/admin/{admin_controller.rb => dashboard_controller.rb} (86%) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 1c513bb..6e1771b 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -1,3 +1,5 @@ +$spacer: 100px; + #admin-page { margin-top: 10px; } diff --git a/app/controllers/admin/admin_controller.rb b/app/controllers/admin/dashboard_controller.rb similarity index 86% rename from app/controllers/admin/admin_controller.rb rename to app/controllers/admin/dashboard_controller.rb index 6c59433..52fd023 100644 --- a/app/controllers/admin/admin_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,4 +1,4 @@ -class Admin::DashBoardController < ApplicationController +class Admin::DashboardController < ApplicationController before_action :require_admin_login, only: :index def index diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 768b58d..14da04c 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -1,32 +1,41 @@ -
+
-
+
<%= "Logged in as #{@user.email}." %> - <%= link_to('Log Out', '#') %> + <%= link_to 'Log Out', '#' %>
-
-
- +
+
+ <%= link_to "View Deleted Events", '#' %>
-
-
- +
+
+

Moderate Suggested Events

<% @events.each do |event| %> -
-
-
- - ... -
+
+
+ Jan +
+ 29 +
+
+ Title +
+ Day and Time +
+ Location +
+
+ +
+
<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c9d2eeb..4e36617 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,9 +12,7 @@ <%= render 'layouts/navbar' %>
-
- <%= yield %> -
+ <%= yield %>
diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 95cd2bd..ae38aee 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Admin::DashBoardController, type: :controller do +RSpec.describe Admin::DashboardController, type: :controller do end From 1df64b2fa726a01d7c56a65054d3e0b15a9acfa5 Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 4 Apr 2018 18:35:23 -0700 Subject: [PATCH 07/11] Make admin panel rows flexible. --- app/assets/stylesheets/admin.scss | 5 ----- app/views/admin/dashboard/index.html.erb | 10 +++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 6e1771b..e69de29 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -1,5 +0,0 @@ -$spacer: 100px; - -#admin-page { - margin-top: 10px; -} diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 14da04c..f680a03 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -1,5 +1,5 @@ -
-
+
+
<%= "Logged in as #{@user.email}." %> @@ -7,19 +7,19 @@
-
+
<%= link_to "View Deleted Events", '#' %>
-
+

Moderate Suggested Events

<% @events.each do |event| %> -
+
Jan
From 7695318715434808f6dc8fe7b1ef16d6bfa9d7fd Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 4 Apr 2018 19:26:47 -0700 Subject: [PATCH 08/11] Hook up log out link to admin router and controller. --- app/controllers/admin/sessions_controller.rb | 7 +++++-- app/views/admin/dashboard/index.html.erb | 18 +++++++++--------- config/routes.rb | 1 + 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index f49fa2b..4dbcb4f 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,6 +1,6 @@ class Admin::SessionsController < ApplicationController - before_action :require_admin_login, only: :index - before_action :redirect_if_logged_in, except: :index + before_action :require_admin_login, only: [:index, :destroy] + before_action :redirect_if_logged_in, except: [:index, :destroy] def new; end @@ -14,4 +14,7 @@ def create render_login_error end end + + def destroy + end end diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index f680a03..f329ed0 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -1,40 +1,40 @@
-
+
<%= "Logged in as #{@user.email}." %> - <%= link_to 'Log Out', '#' %> + <%= link_to 'Log Out', admin_logout_path, method: :post %>
-
+
<%= link_to "View Deleted Events", '#' %>
-
-

Moderate Suggested Events

+
+

Moderate Suggested Events

<% @events.each do |event| %>
-
+
Jan
29
-
+
Title
Day and Time
Location
-
+
-
+
diff --git a/config/routes.rb b/config/routes.rb index 4e85eb3..ae4a09c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ get '/', to: 'dashboard#index' get 'login', to: 'sessions#new' post 'login', to: 'sessions#create' + post 'logout', to: 'sessions#destroy' end get '/submit' => 'submit_events#index' From 753a11dff21e91fa90de90b5ab10d9d31e5e6ebf Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 4 Apr 2018 19:41:30 -0700 Subject: [PATCH 09/11] Add controller spec for admin logout. --- app/controllers/admin/sessions_controller.rb | 3 +++ .../admin/sessions_controller_spec.rb | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 4dbcb4f..6958df4 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -16,5 +16,8 @@ def create end def destroy + session[:user_id] = nil + flash[:success] = "Goodbye! See you next time." + redirect_to root_path end end diff --git a/spec/controllers/admin/sessions_controller_spec.rb b/spec/controllers/admin/sessions_controller_spec.rb index 92ab71f..3deb5d7 100644 --- a/spec/controllers/admin/sessions_controller_spec.rb +++ b/spec/controllers/admin/sessions_controller_spec.rb @@ -16,4 +16,24 @@ end end end + + describe "POST destroy" do + before do + admin = User.create(email: 'example@example.com', password: 'password', admin: true) + session[:user_id] = admin.id + post :destroy + end + + it "sets session id to nil" do + expect(session[:user_id]).to_not be + end + + it "redirects to home page" do + expect(response).to redirect_to(root_path) + end + + it "displays flash logout message" do + expect(flash[:success]).to eq("Goodbye! See you next time.") + end + end end From 7ac1dc01c84870759c473a951c0418cb207c8b28 Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 4 Apr 2018 20:15:31 -0700 Subject: [PATCH 10/11] Refactor user log in and log out feature specs to use macros. --- app/controllers/admin/sessions_controller.rb | 1 - spec/controllers/admin/sessions_controller_spec.rb | 4 ---- spec/features/user_log_in_spec.rb | 9 ++------- spec/features/user_log_out_spec.rb | 9 +++++++++ spec/rails_helper.rb | 2 ++ spec/support/feature_macros.rb | 12 ++++++++++++ 6 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 spec/features/user_log_out_spec.rb create mode 100644 spec/support/feature_macros.rb diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 6958df4..5257db1 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -17,7 +17,6 @@ def create def destroy session[:user_id] = nil - flash[:success] = "Goodbye! See you next time." redirect_to root_path end end diff --git a/spec/controllers/admin/sessions_controller_spec.rb b/spec/controllers/admin/sessions_controller_spec.rb index 3deb5d7..9e023c7 100644 --- a/spec/controllers/admin/sessions_controller_spec.rb +++ b/spec/controllers/admin/sessions_controller_spec.rb @@ -31,9 +31,5 @@ it "redirects to home page" do expect(response).to redirect_to(root_path) end - - it "displays flash logout message" do - expect(flash[:success]).to eq("Goodbye! See you next time.") - end end end diff --git a/spec/features/user_log_in_spec.rb b/spec/features/user_log_in_spec.rb index 98d16f3..51b691d 100644 --- a/spec/features/user_log_in_spec.rb +++ b/spec/features/user_log_in_spec.rb @@ -2,12 +2,7 @@ feature "User Log In" do scenario "with correct credentials" do - User.create(email: 'example@example.com', password: 'password', admin: true) - visit admin_login_path - expect(page).to have_text "Log In" - fill_in "email", with: 'example@example.com' - fill_in "password", with: 'password' - click_button "Log in" - expect(page).to have_text "Welcome to Stayloud LA!" + admin_log_in + expect(page).to have_text "Moderate Suggested Events" end end diff --git a/spec/features/user_log_out_spec.rb b/spec/features/user_log_out_spec.rb new file mode 100644 index 0000000..e7d0b67 --- /dev/null +++ b/spec/features/user_log_out_spec.rb @@ -0,0 +1,9 @@ +require "rails_helper" + +feature "User Log Out" do + scenario "with correct credentials" do + admin_log_in + click_link "Log Out" + expect(page).to have_text "Find A Protest Near You" + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bbe1ba5..44ac27c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -34,7 +34,9 @@ # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true + Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + config.include FeatureMacros, type: :feature # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and # `post` in specs under `spec/controllers`. diff --git a/spec/support/feature_macros.rb b/spec/support/feature_macros.rb new file mode 100644 index 0000000..5797560 --- /dev/null +++ b/spec/support/feature_macros.rb @@ -0,0 +1,12 @@ +module FeatureMacros + def admin_log_in(user = nil) + unless user + user = User.create(email: 'example@example.com', password: 'password', admin: true) + end + visit admin_login_path + expect(page).to have_text "Log In" + fill_in "email", with: user.email + fill_in "password", with: user.password + click_button "Log in" + end +end \ No newline at end of file From 439ece8398539667186ad5d3be4214f97842266e Mon Sep 17 00:00:00 2001 From: Reltre Date: Wed, 4 Apr 2018 20:58:59 -0700 Subject: [PATCH 11/11] Enable js for unhappy path in log in feature spec. --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/login.scss | 3 ++- spec/features/user_log_in_spec.rb | 8 ++++++++ spec/spec_helper.rb | 1 + spec/support/feature_macros.rb | 4 +--- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 82459c0..d2833eb 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -18,6 +18,7 @@ @import "font-awesome"; @import "submit_events"; @import "admin"; + @import "login"; .stats{ diff --git a/app/assets/stylesheets/login.scss b/app/assets/stylesheets/login.scss index 2061fd2..c15f945 100644 --- a/app/assets/stylesheets/login.scss +++ b/app/assets/stylesheets/login.scss @@ -16,7 +16,8 @@ border: 0.1px solid gray; padding: 1px; border-radius: 5px; - display:none; + display: none; + clear: both; p { margin: 1px; diff --git a/spec/features/user_log_in_spec.rb b/spec/features/user_log_in_spec.rb index 51b691d..28e2c85 100644 --- a/spec/features/user_log_in_spec.rb +++ b/spec/features/user_log_in_spec.rb @@ -5,4 +5,12 @@ admin_log_in expect(page).to have_text "Moderate Suggested Events" end + + scenario "with icorrect credentials", js: true do + user = User.create(email: "example@example.com", password: "password") + user.password = "12345" + admin_log_in(user) + save_and_open_page + expect(page).to have_text "No such user found." + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 51df3a2..b4f0de7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,7 @@ # it. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +Capybara.javascript_driver = :webkit RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest diff --git a/spec/support/feature_macros.rb b/spec/support/feature_macros.rb index 5797560..2e211ca 100644 --- a/spec/support/feature_macros.rb +++ b/spec/support/feature_macros.rb @@ -1,8 +1,6 @@ module FeatureMacros def admin_log_in(user = nil) - unless user - user = User.create(email: 'example@example.com', password: 'password', admin: true) - end + user ||= User.create(email: 'example@example.com', password: 'password', admin: true) visit admin_login_path expect(page).to have_text "Log In" fill_in "email", with: user.email