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/admin.scss b/app/assets/stylesheets/admin.scss new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index b7ab955..d2833eb 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,11 +13,12 @@ */ // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables" - @import "bootstrap-sprockets"; @import "bootstrap"; @import "font-awesome-sprockets"; @import "font-awesome"; - @import "submit_events"; + @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/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 0000000..52fd023 --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,22 @@ +class Admin::DashboardController < ApplicationController + before_action :require_admin_login, only: :index + + def index + @user = User.find(current_user) + + @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..5257db1 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,13 +1,9 @@ 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 - def index - render plain: "Hello World!" - end - def create user = User.find_by(email: params[:email]) @@ -18,4 +14,9 @@ def create render_login_error end end + + def destroy + session[:user_id] = nil + redirect_to root_path + end end 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/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb new file mode 100644 index 0000000..f329ed0 --- /dev/null +++ b/app/views/admin/dashboard/index.html.erb @@ -0,0 +1,43 @@ +
+
+
+
+ <%= "Logged in as #{@user.email}." %> + <%= link_to 'Log Out', admin_logout_path, method: :post %> +
+
+
+
+
+ <%= link_to "View Deleted Events", '#' %> +
+
+
+
+

Moderate Suggested Events

+
+
+
+ <% @events.each do |event| %> +
+
+ Jan +
+ 29 +
+
+ Title +
+ Day and Time +
+ Location +
+
+ +
+ +
+
+ <% end %> +
+
\ 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..4e36617 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,10 +6,13 @@ <%= 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 %> +
diff --git a/config/routes.rb b/config/routes.rb index 4d8c7df..ae4a09c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,9 +2,10 @@ root 'welcome#index' namespace :admin do - get '/', to: 'sessions#index' + 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' diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb new file mode 100644 index 0000000..ae38aee --- /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 diff --git a/spec/controllers/admin/sessions_controller_spec.rb b/spec/controllers/admin/sessions_controller_spec.rb index 92ab71f..9e023c7 100644 --- a/spec/controllers/admin/sessions_controller_spec.rb +++ b/spec/controllers/admin/sessions_controller_spec.rb @@ -16,4 +16,20 @@ 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 + end end diff --git a/spec/features/user_log_in_spec.rb b/spec/features/user_log_in_spec.rb index 98d16f3..28e2c85 100644 --- a/spec/features/user_log_in_spec.rb +++ b/spec/features/user_log_in_spec.rb @@ -2,12 +2,15 @@ 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 + + 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/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/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 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 new file mode 100644 index 0000000..2e211ca --- /dev/null +++ b/spec/support/feature_macros.rb @@ -0,0 +1,10 @@ +module FeatureMacros + def admin_log_in(user = nil) + 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 + fill_in "password", with: user.password + click_button "Log in" + end +end \ No newline at end of file