Add misc specs and remove banned attribute from user model (#484)

This commit is contained in:
Ben Halpern 2018-06-22 16:06:04 -04:00 committed by GitHub
parent b44a3eecc2
commit 0755a07713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 215 additions and 4 deletions

View file

@ -0,0 +1,5 @@
class RemoveBannedFromUsers < ActiveRecord::Migration[5.1]
def change
remove_column :users, :banned
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180612214259) do
ActiveRecord::Schema.define(version: 20180622173538) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -596,7 +596,6 @@ ActiveRecord::Schema.define(version: 20180612214259) do
t.integer "articles_count", default: 0, null: false
t.string "available_for"
t.integer "badge_achievements_count", default: 0, null: false
t.boolean "banned", default: false
t.text "base_cover_letter"
t.string "bg_color_hex"
t.boolean "checked_code_of_conduct", default: false

View file

@ -0,0 +1,30 @@
require 'rails_helper'
RSpec.describe BadgeRewarder do
it "rewards birthday badge to birthday folks who registered a year ago" do
user = create(:user, created_at: 366.days.ago)
newer_user = create(:user, created_at: 6.days.ago)
older_user = create(:user, created_at: 390.days.ago)
create(:badge, title: "heyhey")
create(:badge, title: "heysddssdhey")
BadgeRewarder.new.award_yearly_club_badges
expect(user.badge_achievements.size).to eq(1)
expect(newer_user.badge_achievements.size).to eq(0)
expect(older_user.badge_achievements.size).to eq(0)
end
it "rewards beloved comment to folks who have a qualifying comment" do
user = create(:user)
user_other = create(:user)
article = create(:article)
create(:comment, user_id: user.id, positive_reactions_count: 30, commentable_id: article.id)
create(:comment, user_id: user_other.id, positive_reactions_count: 3, commentable_id: article.id)
create(:badge, title: "heweewweyhey")
create(:badge, title: "heweweewewewewyhey")
create(:badge, title: "heewwewewwwwwyhey")
BadgeRewarder.new.award_beloved_comment_badges
expect(user.badge_achievements.size).to eq(1)
expect(user_other.badge_achievements.size).to eq(0)
end
end

View file

@ -0,0 +1,38 @@
# Sigh, this is tough to test.
# require "rails_helper"
# vcr_option = {
# cassette_name: "github_api_readme",
# allow_playback_repeats: "true",
# }
# RSpec.describe GithubTag::GithubReadmeTag, vcr: vcr_option do
# describe "#id" do
# let(:path) { "facebook/react" }
# let(:my_ocktokit_client) { instance_double(Octokit::Client) }
# let(:user) { create(:user) }
# let(:identity) { create(:identity, user_id: user.id) }
# setup { Liquid::Template.register_tag("github", GithubTag) }
# before do
# user = create(:user)
# # create(:identity, user_id: user.id)
# end
# def generate_github_readme(path)
# Liquid::Template.parse("{% github #{path} %}")
# end
# it "rejects github link without domain" do
# expect do
# generate_github_readme("dsdsdsdsdssd3")
# end.to raise_error(StandardError)
# end
# it "rejects invalid github issue link" do
# expect do
# generate_github_readme("/hello/hey/hey/hey")
# end.to raise_error(StandardError)
# end
# end
# end

View file

@ -7,13 +7,13 @@ RSpec.describe "AdditionalContentBoxes", type: :request do
suggestion.update_column(:published, true)
article = create(:article)
get "/additional_content_boxes?article_id=#{article.id}"
expect(response.body).to include(suggestion.title)
expect(response.body).to include CGI.escapeHTML(suggestion.title)
end
it "returns no article if not published/featured" do
suggestion = create(:article)
article = create(:article)
get "/additional_content_boxes?article_id=#{article.id}"
expect(response.body).to_not include(suggestion.title)
expect(response.body).to_not include CGI.escapeHTML(suggestion.title)
end
end
end

View file

@ -0,0 +1,36 @@
require "rails_helper"
RSpec.describe "SocialPreviews", type: :request do
before do
@user = create(:user)
@tag = create(:tag)
@organization = create(:organization)
@article = create(:article, user_id: @user.id)
end
describe "GET /social_previews/article/:id" do
it "renders proper article title" do
get "/social_previews/article/#{@article.id}"
expect(response.body).to include CGI.escapeHTML(@article.title)
end
end
describe "GET /social_previews/user/:id" do
it "renders proper user name" do
get "/social_previews/user/#{@user.id}"
expect(response.body).to include CGI.escapeHTML(@user.name)
end
end
describe "GET /social_previews/user/:id" do
it "renders proper organization name" do
get "/social_previews/organization/#{@organization.id}"
expect(response.body).to include CGI.escapeHTML(@organization.name)
end
end
describe "GET /social_previews/user/:id" do
it "renders proper tag name" do
get "/social_previews/tag/#{@tag.id}"
expect(response.body).to include CGI.escapeHTML(@tag.name)
end
end
end

View file

@ -5,6 +5,27 @@ RSpec.describe "UserSettings", type: :request do
@user = create(:user)
login_as @user
end
describe "GET /settings" do
it "renders various settings tabs properly" do
get "/settings/organization"
expect(response.body).to include("Settings for")
get "/settings/switch-organizations"
expect(response.body).to include("Settings for")
# get "/settings/integrations"
# expect(response.body).to include("Settings for")
get "/settings/billing"
expect(response.body).to include("Settings for")
get "/settings/misc"
expect(response.body).to include("Settings for")
get "/settings/membership"
expect(response.body).not_to include("Settings for")
@user.update_column(:monthly_dues, 5)
get "/settings/membership"
expect(response.body).to include("Settings for")
end
end
describe "PUT /update/:id" do
it "updates summary" do
put "/users/#{@user.id}", params: { user: {tab: "profile", summary: "Hello new summary"} }

View file

@ -0,0 +1,15 @@
require "rails_helper"
RSpec.describe "UsersOnboarding", type: :request do
before do
@user = create(:user, saw_onboarding: false)
login_as @user
end
describe "PATCH /onboarding_update" do
it "updates saw_onboarding boolean" do
patch "/onboarding_update.json", params: {}
expect(@user.saw_onboarding).to eq(true)
end
end
end

View file

@ -0,0 +1,67 @@
---
http_interactions:
- request:
method: get
uri: https://api.github.com/repos/facebook/react/readme
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/vnd.github.html
User-Agent:
- Octokit Ruby Gem 4.8.0
Content-Type:
- application/json
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
response:
status:
code: 401
message: Unauthorized
headers:
Server:
- GitHub.com
Date:
- Fri, 22 Jun 2018 17:33:14 GMT
Content-Type:
- application/json; charset=utf-8
Content-Length:
- '83'
Status:
- 401 Unauthorized
X-Github-Media-Type:
- github.v3; param=html
X-Ratelimit-Limit:
- '60'
X-Ratelimit-Remaining:
- '59'
X-Ratelimit-Reset:
- '1529692394'
Access-Control-Expose-Headers:
- ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining,
X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin:
- "*"
Strict-Transport-Security:
- max-age=31536000; includeSubdomains; preload
X-Frame-Options:
- deny
X-Content-Type-Options:
- nosniff
X-Xss-Protection:
- 1; mode=block
Referrer-Policy:
- origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy:
- default-src 'none'
X-Runtime-Rack:
- '0.024054'
X-Github-Request-Id:
- C3B4:3E2E:257B65C:48AF386:5B2D32DA
body:
encoding: UTF-8
string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
http_version:
recorded_at: Fri, 22 Jun 2018 17:33:14 GMT
recorded_with: VCR 4.0.0