Migrate to Travis CI --skip-ci (#588)
* Create .travis.yml * Update .travis.yml * Add postgresql to travis * Change travis's postgresql version * Add chrome addon to travis * Adjust travis config --skip-ci * Change travis dist * Change travis to use Chrome --skip-ci * Use IntegraitonHelpers --skip-ci * Add no-sandbox option to headless chrome * Add sudo to travis * Fix broken spec * Update travis.yml * Change how travis store bundler cache * Update chromedriver command * Add CodeClimate to travis --skip-ci * Remove deadcode --skip-ci * Remove dead code * Change rspec-retry back to 3 * Add deploy script to travis * Safelist only master for Travis --skip-ci
This commit is contained in:
parent
e407e1ff91
commit
1555388f12
24 changed files with 83 additions and 55 deletions
58
.travis.yml
Normal file
58
.travis.yml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
sudo: required
|
||||
|
||||
language: ruby
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- vendor/bundle
|
||||
- node_modules
|
||||
|
||||
rvm:
|
||||
- 2.5.1
|
||||
|
||||
addons:
|
||||
postgresql: "9.6"
|
||||
chrome: stable
|
||||
|
||||
env:
|
||||
global:
|
||||
- RAILS_ENV=test
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
install:
|
||||
- bundle install --path vendor/bundle
|
||||
- bundle exec chromedriver-update
|
||||
- yarn install
|
||||
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
||||
- chmod +x ./cc-test-reporter
|
||||
|
||||
|
||||
before_script:
|
||||
- cp config/database.yml.travis config/database.yml
|
||||
- psql -c 'create database travis_ci_test;' -U postgres
|
||||
|
||||
script:
|
||||
- bundle exec rails webpacker:compile
|
||||
- bundle exec rake db:schema:load
|
||||
- ./cc-test-reporter before-build
|
||||
- bundle exec rspec spec
|
||||
- ./cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.simplecov.json
|
||||
- yarn test
|
||||
- ./cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.lcov.json
|
||||
- ./cc-test-reporter sum-coverage coverage/codeclimate.*.json
|
||||
- ./cc-test-reporter upload-coverage
|
||||
|
||||
deploy:
|
||||
provider: heroku
|
||||
api_key: $HEROKU_AUTH_TOKEN
|
||||
app:
|
||||
master: practicaldev
|
||||
run:
|
||||
- "rake db:migrate"
|
||||
- restart
|
||||
|
||||
after_deploy:
|
||||
- ./after_deploy.sh
|
||||
1
Gemfile
1
Gemfile
|
|
@ -133,7 +133,6 @@ group :test do
|
|||
gem "fake_stripe", "~> 0.1"
|
||||
gem "launchy", "~> 2.4"
|
||||
gem "pundit-matchers", "~> 1.6"
|
||||
gem "rack_session_access", "~> 0.2"
|
||||
gem "rails-controller-testing", "~> 1.0"
|
||||
gem "ruby-prof", "~> 0.17", require: false
|
||||
gem "selenium-webdriver", "~> 3.12"
|
||||
|
|
|
|||
|
|
@ -648,9 +648,6 @@ GEM
|
|||
rack-test (1.0.0)
|
||||
rack (>= 1.0, < 3)
|
||||
rack-timeout (0.5.1)
|
||||
rack_session_access (0.2.0)
|
||||
builder (>= 2.0.0)
|
||||
rack (>= 1.0.0)
|
||||
rails (5.1.6)
|
||||
actioncable (= 5.1.6)
|
||||
actionmailer (= 5.1.6)
|
||||
|
|
@ -994,7 +991,6 @@ DEPENDENCIES
|
|||
pusher (~> 1.3)
|
||||
rack-host-redirect (~> 1.3)
|
||||
rack-timeout (~> 0.5)
|
||||
rack_session_access (~> 0.2)
|
||||
rails (~> 5.1)
|
||||
rails-assets-airbrake-js-client (~> 0.9)!
|
||||
rails-controller-testing (~> 1.0)
|
||||
|
|
|
|||
|
|
@ -159,16 +159,9 @@ The following technologies are used for testing:
|
|||
* **Rspec**
|
||||
* **Capybara** with **selenium-webdriver**
|
||||
* **chromedriver-helper** for standard JS testing.
|
||||
* **`rack_session_access`**
|
||||
* **Warden**
|
||||
* **guard-rspec** for automated testing
|
||||
* [Jest](https://facebook.github.io/jest) for testing in the front-end.
|
||||
|
||||
#### When should I use `login_via_session_as(:user)` vs `login_as(:user)`?
|
||||
|
||||
* `login_as(:user)` uses Warden's stubbing actions to make the application think that a user is signed in but without all of the overhead of actually signing them in. Recommended for view test.
|
||||
* `login_via_session_as(:user)` uses `rack_session_access` to modify application's session. It is integrated with Devise so current_user won't be nil. Recommended for feature test.
|
||||
|
||||
## Previewing emails in development
|
||||
|
||||
You can modify the test in `/test/mailers/previews`
|
||||
|
|
|
|||
5
after_deploy.sh
Normal file
5
after_deploy.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# This is Airbrake deployment tracking
|
||||
|
||||
REPOSITORY=https://github.com/thepracticaldev/dev.to_private/
|
||||
REVISION="$(git rev-parse HEAD)"
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"environment":"production","repository":"'${REPOSITORY}'","revision":"'${REVISION}'"}' "https://airbrake.io/api/v4/projects/${AIRBRAKE_PROJECT_ID}/deploys?key=${AIRBRAKE_PROJECT_KEY}"
|
||||
3
config/database.yml.travis
Normal file
3
config/database.yml.travis
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
test:
|
||||
adapter: postgresql
|
||||
database: travis_ci_test
|
||||
|
|
@ -46,8 +46,6 @@ Rails.application.configure do
|
|||
# Print deprecation notices to the stderr.
|
||||
config.active_support.deprecation = :stderr
|
||||
|
||||
config.middleware.use RackSessionAccess::Middleware
|
||||
|
||||
# Raises error for missing translations
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ feature "Admin bans user" do
|
|||
let(:user) { create(:user) }
|
||||
|
||||
background do
|
||||
login_via_session_as admin
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ feature "Admin creates new event" do
|
|||
let(:admin) { create(:user, :super_admin) }
|
||||
|
||||
background do
|
||||
login_via_session_as admin
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ feature "Admin warns user" do
|
|||
let(:user) { create(:user) }
|
||||
|
||||
background do
|
||||
login_via_session_as admin
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ feature "Banned user" do
|
|||
let(:banned_user) { create(:user, :banned) }
|
||||
|
||||
scenario "tries to create an article" do
|
||||
login_via_session_as banned_user
|
||||
sign_in banned_user
|
||||
expect { visit "/new" }.to raise_error("BANNED")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# after { StripeMock.stop }
|
||||
|
||||
# background do
|
||||
# login_via_session_as user
|
||||
# sign_in user
|
||||
# end
|
||||
|
||||
# scenario "User navigates to settings page and adds a card" do
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ RSpec.feature "Deleting Article", js: true do
|
|||
end
|
||||
|
||||
scenario "author of article deletes own article" do
|
||||
login_via_session_as author
|
||||
sign_in author
|
||||
delete_article_via_dashboard
|
||||
expect(page).to have_text("Write your first post now")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ RSpec.describe "Editing Comment", type: :feature, js: true do
|
|||
end
|
||||
|
||||
before do
|
||||
login_via_session_as user
|
||||
sign_in user
|
||||
comment
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ feature "Editing with an editor" do
|
|||
end
|
||||
|
||||
background do
|
||||
login_via_session_as user
|
||||
sign_in user
|
||||
end
|
||||
|
||||
scenario "user click the edit-post button", js: true, retry: 3 do
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# let(:user) { create(:user, saw_onboarding: true) }
|
||||
|
||||
# before do
|
||||
# login_via_session_as user
|
||||
# sign_in user
|
||||
# end
|
||||
|
||||
# describe "via their profile page" do
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ RSpec.describe "Creating Comment", type: :feature, js: true do
|
|||
end
|
||||
|
||||
before do
|
||||
login_via_session_as user
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "User fills out comment box normally" do
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ feature "Seeing checklist on home page" do
|
|||
let(:user) { create(:user) }
|
||||
|
||||
background do
|
||||
login_via_session_as user
|
||||
sign_in user
|
||||
end
|
||||
|
||||
# scenario "user visits home page to see checklist seen", js: true do
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ RSpec.describe "Organization setting page(/settings/organization)", type: :featu
|
|||
let(:organization) { create(:organization) }
|
||||
|
||||
before do
|
||||
login_via_session_as user
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "user creates an organization" do
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ feature "Using the editor" do
|
|||
let(:rich_template) { File.read(File.join(File.dirname(__FILE__), rich_dir)) }
|
||||
|
||||
background do
|
||||
login_via_session_as user
|
||||
sign_in user
|
||||
end
|
||||
|
||||
def read_from_file(dir)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ RSpec.describe BlockPolicy do
|
|||
let(:valid_attributes) do
|
||||
%i[input_html input_css input_javascript featured index_position publish_now]
|
||||
end
|
||||
|
||||
|
||||
context "when not signed in" do
|
||||
let(:user) { nil }
|
||||
|
||||
|
|
@ -24,8 +24,6 @@ RSpec.describe BlockPolicy do
|
|||
context "when user is signed in as a super admin" do
|
||||
let(:user) { build(:user, :super_admin) }
|
||||
|
||||
before { login_as user }
|
||||
|
||||
it { is_expected.to permit_actions(%i[index show new edit create update destroy]) }
|
||||
it { is_expected.to permit_mass_assignment_of(valid_attributes) }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ
|
|||
require "spec_helper"
|
||||
require "webmock/rspec"
|
||||
require "capybara/rspec"
|
||||
require "rack_session_access/capybara"
|
||||
require "stream_rails"
|
||||
require "selenium/webdriver"
|
||||
require "rspec/retry"
|
||||
|
|
@ -61,7 +60,7 @@ RSpec.configure do |config|
|
|||
config.include FactoryBot::Syntax::Methods
|
||||
|
||||
# Apply rack_session_access integrated with devise.
|
||||
config.include FeatureHelpers, type: :feature
|
||||
config.include Devise::Test::IntegrationHelpers, type: :feature
|
||||
|
||||
# show retry status in spec process
|
||||
config.verbose_retry = true
|
||||
|
|
@ -202,7 +201,7 @@ end
|
|||
|
||||
Capybara.register_driver :headless_chrome do |app|
|
||||
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
||||
chromeOptions: { args: %w(headless disable-gpu window-size=1400,2000) },
|
||||
chromeOptions: { args: %w(headless disable-gpu no-sandbox window-size=1400,2000) },
|
||||
)
|
||||
|
||||
Capybara::Selenium::Driver.new app,
|
||||
|
|
@ -212,6 +211,6 @@ end
|
|||
|
||||
# The current driveres implemented are
|
||||
# - chrome-helper (:chrome) => Use this for browser-based testing
|
||||
# - headless-chrome (:headless_chrome) => headless version of chrome-helper. Work but slow.
|
||||
# - headless-chrome (:headless_chrome) => headless version of chrome-helper
|
||||
|
||||
Capybara.javascript_driver = :headless_chrome
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
module FeatureHelpers
|
||||
def login_via_session_as(user)
|
||||
page.set_rack_session('warden.user.user.key' => User.serialize_into_session(user))
|
||||
end
|
||||
end
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
RSpec.configure do |config|
|
||||
include Warden::Test::Helpers
|
||||
Warden.test_mode!
|
||||
|
||||
config.after(:each) do
|
||||
Warden.test_reset!
|
||||
end
|
||||
|
||||
# def sign_in(user, opts = {})
|
||||
# login_as(user, opts)
|
||||
# end
|
||||
#
|
||||
# def sign_out(*scopes)
|
||||
# logout(*scopes)
|
||||
# end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue