Skip to content

Commit

Permalink
fix: environment database
Browse files Browse the repository at this point in the history
  • Loading branch information
aristotelesbr committed Jan 30, 2024
1 parent 6eb9a8a commit 67fe1e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
run: RACK_ENV='test' bundle exec ruby db/setup.rb

- name: Run tests
run: bundle exec rspec
run: RACK_ENV='test' bundle exec rspec

4 changes: 3 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def render(view)

# DATABASE CONNECTION
#
def database = @database ||= SQLite3::Database.new('db/teachers.db')
def database
@database ||= SQLite3::Database.new ENV['RACK_ENV'] == 'test' ? 'db/teachers_test.db' : 'db/teachers.db'
end

# SQL QUERIES
#
Expand Down
11 changes: 11 additions & 0 deletions spec/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
::RSpec.describe('RatingApp') do
describe 'requests' do
context 'GET /' do
before do
@database = SQLite3::Database.new('db/teachers_test.db')
@database.execute('INSERT INTO teachers (name) VALUES ("Sócrates"), ("Aristóteles"), ("Epicteto"), ("João")')
end

after do
@database.execute('DELETE FROM ratings')

@database.close
end

it 'returns 200' do
get '/'
expect(last_response).to be_ok
Expand Down

0 comments on commit 67fe1e6

Please sign in to comment.