Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
GabeIsman committed Sep 11, 2020
1 parent a49ec90 commit f37b2c0
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gem 'aws-sdk-sqs', '~> 1.30'

group :development, :test do
gem 'byebug'
gem 'rspec-rails', '~> 3.8'
gem 'rspec-rails'
gem 'guard-rspec', require: false
gem 'factory_bot_rails', '~> 6.1'
gem 'database_cleaner'
Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
aws-eventstream (1.1.0)
aws-partitions (1.367.0)
aws-partitions (1.368.0)
aws-sdk-core (3.105.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
Expand Down Expand Up @@ -248,14 +248,14 @@ GEM
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (3.9.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-support (~> 3.9.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.3)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
Expand Down Expand Up @@ -350,7 +350,7 @@ DEPENDENCIES
rails (~> 6.0)
rails-controller-testing
rails_12factor
rspec-rails (~> 3.8)
rspec-rails
rspec_junit_formatter
sass-rails (~> 5.0)
sdoc (~> 1.0.0)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def embed_find_page # POST request

def embed_update_page_selector # POST request
page = Page.find_by(id: params[:id])

page.css_selector = params[:css_selector]
if page.save
render json: page
Expand Down
1 change: 0 additions & 1 deletion app/controllers/embed_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class EmbedController < ApplicationController

skip_before_action :verify_authenticity_token, only: [:inject]
before_action :authorize, only: [:iframe]

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/integrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class IntegrationsController < ApplicationController
before_action :authorize

def index
@slack_integrations = SlackIntegration.all
@sqs_integrations = SqsIntegration.all
@sqs_integrations = SqsIntegration.all
end
end
1 change: 0 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ def destroy
cookies.delete(:user_id)
redirect_to root_path
end

end
1 change: 1 addition & 0 deletions app/controllers/slack_integrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class SlackIntegrationsController < ApplicationController
before_action :set_slack_integration, only: [:show, :edit, :update, :destroy]
before_action :authorize

# GET /slack_integrations
def index
Expand Down
1 change: 1 addition & 0 deletions app/controllers/sqs_integrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class SqsIntegrationsController < ApplicationController
before_action :set_sqs_integration, only: [:show, :edit, :update, :destroy]
before_action :authorize

# GET /sqs_integrations
def index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class StaticController < ApplicationController
before_action :authorize

def help
path = File.join(Rails.root, 'data', 'help.md')
Expand All @@ -8,5 +9,4 @@ def help

def feed
end

end
1 change: 0 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class UsersController < ApplicationController

before_action :authorize
before_action :set_user, only: [:show, :edit, :update, :destroy]

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/watching_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class WatchingController < ApplicationController

before_action :authorize

def feed
@changes = Change.order('created_at DESC').first(20)
end

end
2 changes: 0 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

config.action_mailer.delivery_method = :letter_opener

config.hosts << "klaxon.test"

config.force_ssl = (ENV.fetch('KLAXON_FORCE_SSL', 'false').to_s.downcase == 'true')

# Raises error for missing translations
Expand Down
72 changes: 52 additions & 20 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,57 @@

RSpec.describe ApiController, type: :controller do

# describe "GET #subscriptions" do
# it "returns http success" do
# get :subscriptions
# expect(response).to have_http_status(:success)
# end
# end

# describe "GET #users" do
# it "returns http success" do
# get :users
# expect(response).to have_http_status(:success)
# end
# end

# describe "GET #pages" do
# it "returns http success" do
# get :pages
# expect(response).to have_http_status(:success)
# end
# end
before(:each) {
WebMock.allow_net_connect!
login
}

describe "/page-preview" do
it "can query the tmp homepage" do

url = 'https://www.themarshallproject.org'
css_selector = 'header'

get(:page_preview, params: { url: url, css_selector: css_selector })

expect(response).to have_http_status(:success)

data = JSON.parse(response.body)
expect(data['css_selector']).to eq css_selector
expect(data['url']).to eq url
expect(data['match_text']).to include 'About'
end
end

it "can get the users" do
get(:users)
expect(JSON.parse(response.body).count).to be > 0
end

it "creates a page by url and can update that page's selector" do
url = "http://www.nytimes.com/"
selector = ".first-column-region .story"

@user = current_user

# create the page
post(:embed_find_page, params: { url: url })
expect(response).to have_http_status(:success)
data = JSON.parse(response.body)
expect(data['url']).to eq url
expect(data['css_selector']).to eq nil
page = Page.find_by(url: url)
expect(page.user).to eq @user

# update the page
post(:embed_update_page_selector, params: { id: page.id, css_selector: selector })
data = JSON.parse(response.body)
expect(data['css_selector']).to eq selector
expect(data['user_id']).to eq @user.id
end

it "has stats"
it "has subscriptions"
it "has pages"

end
4 changes: 2 additions & 2 deletions spec/controllers/integrations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'rails_helper'

RSpec.describe IntegrationsController, type: :controller do

describe "GET #index" do
before (:each) { login }

it "returns http success" do
get :index
expect(response).to have_http_status(:success)
end
end

end
2 changes: 2 additions & 0 deletions spec/controllers/slack_integrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
skip("Add a hash of attributes invalid for your model")
}

before(:each) { login }

describe "GET #index" do
it "assigns all slack_integrations as @slack_integrations" do
slack_integration = SlackIntegration.create! valid_attributes
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/sqs_integrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
}
}

before(:each) { login }

describe "GET #index" do
it "assigns all sqs_integrations as @sqs_integrations" do
sqs_integration = SqsIntegration.create! valid_attributes
Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

config.example_status_persistence_file_path = Rails.root.join('tmp/examples.txt')

config.include FactoryBot::Syntax::Methods
config.include LoginHelper

config.use_transactional_fixtures = false

Expand Down
59 changes: 0 additions & 59 deletions spec/requests/api_controller_spec.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/requests/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@

RSpec.describe "Pages", type: :request do
describe "GET /pages" do
it "works! (now write some real specs)"
# do
# get pages_path
# expect(response).to have_http_status(200)
# end
end
end
4 changes: 0 additions & 4 deletions spec/requests/slack_integrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

RSpec.describe "SlackIntegrations", type: :request do
describe "GET /slack_integrations" do
it "works! (now write some real specs)" do
get slack_integrations_path
expect(response).to have_http_status(200)
end
end
end
4 changes: 0 additions & 4 deletions spec/requests/sqs_integrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

RSpec.describe "SqsIntegrations", type: :request do
describe "GET /sqs_integrations" do
it "works!" do
get sqs_integrations_path
expect(response).to have_http_status(200)
end
end
end
8 changes: 0 additions & 8 deletions spec/requests/static_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@

RSpec.describe StaticController, type: :request do

before(:each) do
WebMock.allow_net_connect!

# login
@user = User.where(email: '[email protected]').first_or_create
get(token_session_path, token: LoginToken.create(user: @user))
end

end
4 changes: 0 additions & 4 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

RSpec.describe "Users", type: :request do
describe "GET /users" do
# it "works! (now write some real specs)" do
# get users_path
# expect(response).to have_http_status(200)
# end
end
end
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down
5 changes: 5 additions & 0 deletions spec/support/cookies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ActionDispatch::Cookies::CookieJar
def encrypted; self; end
def signed; self; end
def permanent; self; end
end
10 changes: 10 additions & 0 deletions spec/support/login_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module LoginHelper
def login(user=nil)
user = User.where(email: '[email protected]').first_or_create if user.nil?
request.cookies[:user_id] = user.id
end

def current_user
User.find(request.cookies[:user_id])
end
end

0 comments on commit f37b2c0

Please sign in to comment.