Skip to content

Commit ae07ce2

Browse files
Fix travis build problems (#380)
* Run precompiling assets against test db. * Fix failing tests because date after 2020-02-02. * Use a data type postgres understands. * Compile assets for tests to same directory. * Swap the actual database config against one that builds against sqlite in production. * Do not force install of sqlite as it is a dependency for all environments anyway. * Add comments * Run deployment from dev instead of this branch.
1 parent 94f2cba commit ae07ce2

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ RUN bundle install --without development test
2323

2424
COPY . .
2525
RUN yarn install --check-files
26-
26+
# We need a database to precompile the assets. Compiling at run time is impossible; node fails because there is not enough memory.
27+
# Obviously, we do not want to connect to the real production database from whatever build server we run on.
28+
# So we exchange the real databas econfiguration that points to the Heroku database with one that points to a SQLite database we can quickly create on ephemeral storage.
29+
RUN cp ./config/database.yml ./config/database_real.yml
30+
RUN cp ./config/database_travis_build.yml ./config/database.yml
31+
# db schema needs to be created, so run migrations first
32+
RUN ./bin/rails db:migrate
33+
# now assets can be compiled
2734
RUN ./bin/rails assets:precompile
35+
# revert the change so we speak to the production database later
36+
RUN cp ./config/database_real.yml ./config/database.yml
2837
EXPOSE 3000
2938
ENV RAILS_SERVE_STATIC_FILES=true
3039
ENV RAILS_LOG_TO_STDOUT=true

config/database_travis_build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SQLite version 3.x
2+
# gem install sqlite3
3+
#
4+
# Ensure the SQLite 3 gem is defined in your Gemfile
5+
# gem 'sqlite3'
6+
#
7+
default: &default
8+
adapter: sqlite3
9+
pool: 5
10+
timeout: 5000
11+
12+
development:
13+
<<: *default
14+
database: db/development.sqlite3
15+
16+
# Warning: The database defined as "test" will be erased and
17+
# re-generated from your development database when you run "rake".
18+
# Do not set this db to the same as development or production.
19+
test:
20+
<<: *default
21+
database: db/test.sqlite3
22+
23+
#this config is used in deployment. To compile production assets, we need a database. We can not use PostGres since this build runs on a Travis machine, so use sqlite in this case.
24+
production:
25+
<<: *default
26+
database: db/test.sqlite3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class AddIndexToPollOptions < ActiveRecord::Migration[5.2]
22
def change
3-
add_column :poll_options, :index, :number
3+
add_column :poll_options, :index, :integer
44
end
55
end

spec/controllers/lectures_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
RSpec.describe LecturesController, type: :controller do
55
let(:valid_attributes) {
6-
{ name: "SWT", enrollment_key: "swt", status: "created", date: "2020-02-02", start_time: "2020-01-01 10:10:00", end_time: "2020-01-01 10:20:00", questions_enabled: true, polls_enabled: true }
6+
{ name: "SWT", enrollment_key: "swt", status: "created", date: Date.tomorrow, start_time: "2020-01-01 10:10:00", end_time: "2020-01-01 10:20:00", questions_enabled: true, polls_enabled: true }
77
}
88
let(:valid_attributes_with_lecturer) {
99
valid_attributes.merge(lecturer: FactoryBot.create(:user, :lecturer, email: "test@test.de"))

spec/models/lecture_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe Lecture, type: :model do
44
let(:valid_attributes) {
5-
{ name: "SWT", enrollment_key: "swt", status: "created", date: "2020-02-02", start_time: "2020-01-01 10:10:00", end_time: "2020-01-01 10:20:00", questions_enabled: true, polls_enabled: true }
5+
{ name: "SWT", enrollment_key: "swt", status: "created", date: Date.tomorrow, start_time: "2020-01-01 10:10:00", end_time: "2020-01-01 10:20:00", questions_enabled: true, polls_enabled: true }
66
}
77
let(:valid_attributes_with_lecturer) {
88
valid_attributes.merge(lecturer: FactoryBot.create(:user, :lecturer, email: "test@test.de"))

spec/views/lectures/edit.html.erb_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
status: "created",
1010
lecturer: FactoryBot.create(:user, :lecturer),
1111
course: @course,
12-
date: "2020-02-02",
12+
date: Date.tomorrow,
1313
start_time: "2020-01-01 10:10:00",
1414
end_time: "2020-01-01 10:20:00"
1515
))

0 commit comments

Comments
 (0)