Add more request specs (#460)
* Remove email blank onboarding redirect * Add authorization specs for video upload * Add registration spec * Remove skip before actions for signup complete * Use new param for abuse reports * Remove else because it never runs * Add more dashboard request specs * Use let with no bang in case there are errors
This commit is contained in:
parent
0941b2e4fb
commit
263a74bcb6
20 changed files with 157 additions and 79 deletions
|
|
@ -8,8 +8,6 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# before_action :require_http_auth if ENV["APP_NAME"] == "dev_stage"
|
||||
|
||||
before_action :ensure_signup_complete
|
||||
|
||||
#before_action :customize_params
|
||||
|
||||
def require_http_auth
|
||||
|
|
@ -22,15 +20,6 @@ class ApplicationController < ActionController::Base
|
|||
raise ActionController::RoutingError.new("Not Found")
|
||||
end
|
||||
|
||||
def ensure_signup_complete
|
||||
return if controller_name == "users" || controller_name == "onboarding" || params[:confirmation_token].present?
|
||||
return if !request.get?
|
||||
if current_user && current_user.email.blank?
|
||||
redirect_to "/getting-started"
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def efficient_current_user_id
|
||||
if session["warden.user.user.key"].present?
|
||||
session["warden.user.user.key"].flatten[0]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class AsyncInfoController < ApplicationController
|
||||
skip_before_action :ensure_signup_complete
|
||||
include Devise::Controllers::Rememberable
|
||||
|
||||
def base_data
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ class DashboardsController < ApplicationController
|
|||
@articles = @user.organization.articles.order("created_at DESC").decorate
|
||||
elsif @user
|
||||
@articles = @user.articles.order("created_at DESC").decorate
|
||||
else
|
||||
redirect_to "/enter"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class FeedbackMessagesController < ApplicationController
|
|||
#{generate_user_detail}
|
||||
Category: #{feedback_message_params[:category]}
|
||||
Message: #{feedback_message_params[:message]}
|
||||
URL: #{params[:url]}
|
||||
URL: #{params[:reported_url]}
|
||||
HEREDOC
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class FollowedArticlesController < ApplicationController
|
||||
skip_before_action :ensure_signup_complete
|
||||
|
||||
caches_action :index,
|
||||
:cache_path => Proc.new { "followed_articles_#{current_user.id}__#{current_user.updated_at}__#{user_signed_in?.to_s}" },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class FollowsController < ApplicationController
|
||||
skip_before_action :ensure_signup_complete
|
||||
|
||||
def show
|
||||
unless current_user
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
class GiveawaysController < ApplicationController
|
||||
# GET /giveaways/new
|
||||
skip_before_action :ensure_signup_complete
|
||||
|
||||
def new
|
||||
@user = current_user
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class Notifications::CountsController < ApplicationController
|
||||
skip_before_action :ensure_signup_complete
|
||||
def index
|
||||
count = GetUnseenNotificationsService.new(current_user).get
|
||||
render plain: count.to_s
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Notifications::ReadsController < ApplicationController
|
||||
skip_before_action :ensure_signup_complete
|
||||
|
||||
def create
|
||||
result = ""
|
||||
result = ReadNotificationsService.new(current_user).mark_as_read if current_user
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
class OnboardingController < ApplicationController
|
||||
|
||||
def index
|
||||
if Rails.env.test?
|
||||
redirect_to "/"
|
||||
elsif current_user.email.blank? && current_user.unconfirmed_email.blank?
|
||||
basic_info
|
||||
else
|
||||
redirect_to "/settings"
|
||||
end
|
||||
end
|
||||
|
||||
def basic_info
|
||||
@user = current_user
|
||||
render :basic_info
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
class ReadingListItemsController < ApplicationController
|
||||
before_action :set_cache_control_headers, only: [:index]
|
||||
skip_before_action :ensure_signup_complete
|
||||
|
||||
def index
|
||||
@reading_list_items_index = true
|
||||
set_surrogate_key_header "reading-list-index"
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ class StoriesController < ApplicationController
|
|||
before_action :authenticate_user!, except: [:index,:search,:show, :feed, :new]
|
||||
before_action :set_cache_control_headers, only: [:index, :search, :show]
|
||||
|
||||
skip_before_action :ensure_signup_complete
|
||||
|
||||
def index
|
||||
return handle_user_or_organization_or_podcast_index if params[:username]
|
||||
return handle_tag_index if params[:tag]
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
<div class="onboarding-container container">
|
||||
|
||||
<h1>Thanks for signing up</h1>
|
||||
<h2>A couple things to get started</h2>
|
||||
<%= form_for @user do |f| %>
|
||||
<%= f.email_field :email, placeholder: "Email Address" %>
|
||||
<%= f.text_area :summary,
|
||||
placeholder: "Short personal summary: Job, programming languages, etc.",
|
||||
maxlength: 200 %>
|
||||
<%= f.submit "SUBMIT", class: "cta" %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
|
@ -21,9 +21,14 @@
|
|||
<% end %>
|
||||
<% if current_user.email.blank? %>
|
||||
<div class="finish-notice">
|
||||
Provide email to complete your profile
|
||||
Confirm your email to complete your profile
|
||||
<div class="small">
|
||||
while you're at it, go ahead and fill everything out.<br/>connect your <%= (@user.twitter_username.blank?) ? "twitter":"github" %> account as well to complete your identity.
|
||||
while you're at it, go ahead and fill everything out.<br/>
|
||||
<% if @user.twitter_username.blank? %>
|
||||
connect your twitter account as well to complete your identity.
|
||||
<% elsif @user.github_username.blank? %>
|
||||
connect your github account as well to complete your identity.
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -232,8 +232,6 @@ Rails.application.routes.draw do
|
|||
|
||||
get "/badge/:slug" => "badges#show"
|
||||
|
||||
get "/getting-started" => "onboarding#index"
|
||||
|
||||
get "/top/:timeframe" => "stories#index"
|
||||
|
||||
get "/:timeframe" => "stories#index", constraints: { timeframe: /latest/}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ FactoryBot.define do
|
|||
after(:build) { |user| user.add_role(:banned) }
|
||||
end
|
||||
|
||||
trait :video_permission do
|
||||
after(:build) { |user| user.add_role :video_permission }
|
||||
end
|
||||
|
||||
trait :ignore_after_callback do
|
||||
after(:build) do |user|
|
||||
user.define_singleton_method(:subscribe_to_mailchimp_newsletter) {}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,94 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Dashboards", type: :request do
|
||||
let(:user) { create(:user) }
|
||||
let(:article) { create(:article, user_id: user.id) }
|
||||
let(:user) { create(:user) }
|
||||
let(:second_user) { create(:user) }
|
||||
let(:super_admin) { create(:user, :super_admin) }
|
||||
let(:article) { create(:article, user_id: user.id) }
|
||||
|
||||
describe "GET /dashboard" do
|
||||
context "when logged-in" do
|
||||
before do
|
||||
article
|
||||
login_as user
|
||||
context "when not logged in" do
|
||||
it "redirects to /enter" do
|
||||
get "/dashboard"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
it "renders user's articles" do
|
||||
login_as user
|
||||
article
|
||||
get "/dashboard"
|
||||
expect(response.body).to include CGI.escapeHTML(article.title)
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as a super admin" do
|
||||
it "renders the specified user's articles" do
|
||||
article
|
||||
user
|
||||
login_as super_admin
|
||||
get "/dashboard/#{user.username}"
|
||||
expect(response.body).to include CGI.escapeHTML(article.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /dashboard/organization" do
|
||||
let(:organization) { create(:organization) }
|
||||
|
||||
context "when not logged in" do
|
||||
it "redirects to /enter" do
|
||||
get "/dashboard/organization"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
it "renders user's organization articles" do
|
||||
organization = create(:organization)
|
||||
user.update(organization_id: organization.id, org_admin: true)
|
||||
article.update(organization_id: organization.id)
|
||||
login_as user
|
||||
get "/dashboard/organization"
|
||||
expect(response.body).to include CGI.escapeHTML(organization.name.upcase)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "redirects to /enter if no current_user" do
|
||||
get "/dashboard/organization"
|
||||
expect(response.body).to redirect_to("/enter")
|
||||
describe "GET /dashboard/following_users" do
|
||||
context "when not logged in" do
|
||||
it "redirects to /enter" do
|
||||
get "/dashboard/following_users"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
it "renders the current user's followings" do
|
||||
user.follow second_user
|
||||
login_as user
|
||||
get "/dashboard/following_users"
|
||||
expect(response.body).to include second_user.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /dashboard/user_followers" do
|
||||
context "when not logged in" do
|
||||
it "redirects to /enter" do
|
||||
get "/dashboard/user_followers"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
it "renders the current user's followers" do
|
||||
second_user.follow user
|
||||
login_as user
|
||||
get "/dashboard/user_followers"
|
||||
expect(response.body).to include second_user.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ RSpec.describe "feedback_messages", type: :request do
|
|||
end
|
||||
|
||||
context "when a logged in user submits report" do
|
||||
let!(:user) { create(:user) }
|
||||
let(:user) { create(:user) }
|
||||
let(:mail_message) { instance_double(Mail::Message, deliver: true) }
|
||||
|
||||
before do
|
||||
|
|
|
|||
22
spec/requests/registration_spec.rb
Normal file
22
spec/requests/registration_spec.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Registrations", type: :request do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
describe "GET /enter" do
|
||||
context "when not logged in" do
|
||||
it "shows the sign in page" do
|
||||
get "/enter"
|
||||
expect(response.body).to include "Sign In or Create Your Account"
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
it "redirects to /dashboard" do
|
||||
login_as user
|
||||
get "/enter"
|
||||
is_expected.to redirect_to("/dashboard?signed-in-already&t=#{Time.now.to_i}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,22 +1,60 @@
|
|||
# http://localhost:3000/api/comments?a_id=23
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Videos", type: :request do
|
||||
before do
|
||||
@user = create(:user)
|
||||
login_as @user
|
||||
end
|
||||
let(:unauthorized_user) { create(:user) }
|
||||
let(:authorized_user) { create(:user, :video_permission) }
|
||||
|
||||
describe "GET /videos/new" do
|
||||
it "redirects if non permission" do
|
||||
get "/videos/new"
|
||||
expect(response.body).to include("You are being")
|
||||
context "when not authorized" do
|
||||
it "redirects non-logged in users" do
|
||||
get "/videos/new"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
|
||||
it "redirects logged in users" do
|
||||
login_as unauthorized_user
|
||||
get "/videos/new"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
it "renders video page if has permission" do
|
||||
@user.add_role(:video_permission)
|
||||
get "/videos/new"
|
||||
expect(response.body).to include("Upload Video File")
|
||||
context "when authorized" do
|
||||
it "allows authorized users" do
|
||||
login_as authorized_user
|
||||
get "/videos/new"
|
||||
expect(response.body).to include "Upload Video File"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /videos" do
|
||||
context "when not authorized" do
|
||||
it "redirects non-logged in users" do
|
||||
post "/videos"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
|
||||
it "redirects logged in users" do
|
||||
login_as unauthorized_user
|
||||
post "/videos"
|
||||
is_expected.to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when authorized" do
|
||||
before do
|
||||
login_as authorized_user
|
||||
end
|
||||
|
||||
valid_params = {
|
||||
article: {
|
||||
video: "something.mp4"
|
||||
}
|
||||
}
|
||||
|
||||
xit "creates an article for the logged in user" do
|
||||
post "/videos", params: valid_params
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue