Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
19 changes: 19 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ gem 'rails', '~> 5.2.3'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'skylight'
gem 'pghero'
gem 'activerecord-import'
gem 'oj'
gem 'progress_bar'
gem 'strong_migrations'
gem 'newrelic_rpm'



group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -17,9 +26,19 @@ group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'bullet'
end

group :test do
gem 'rspec'
gem 'rspec-rails'
gem 'rspec-sqlimit'
gem 'test-prof'
gem 'database_cleaner'
gem 'n_plus_one_control'
gem 'factory_bot_rails'
gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master'
gem 'pry-byebug'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
112 changes: 111 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
GIT
remote: https://github.com/stympy/faker.git
revision: 59a92644d5583828add1c68351074f6e52c6deb6
branch: master
specs:
faker (1.9.3)
i18n (>= 0.7)
pastel (~> 0.7.2)
thor (~> 0.20.0)
tty-pager (~> 0.12.0)
tty-screen (~> 0.6.5)
tty-tree (~> 0.2.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -33,6 +46,8 @@ GEM
activemodel (= 5.2.3)
activesupport (= 5.2.3)
arel (>= 9.0)
activerecord-import (1.0.1)
activerecord (>= 3.2)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
Expand All @@ -47,13 +62,26 @@ GEM
bootsnap (1.4.2)
msgpack (~> 1.0)
builder (3.2.3)
bullet (5.9.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
database_cleaner (1.7.0)
diff-lcs (1.3)
equatable (0.5.0)
erubi (1.8.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.2)
factory_bot (~> 5.0.2)
railties (>= 4.2.0)
ffi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
highline (2.0.2)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
listen (3.1.5)
Expand All @@ -73,12 +101,30 @@ GEM
mini_portile2 (2.4.0)
minitest (5.11.3)
msgpack (1.2.9)
n_plus_one_control (0.3.1)
newrelic_rpm (6.2.0.354)
nio4r (2.3.1)
nokogiri (1.10.2)
mini_portile2 (~> 2.4.0)
oj (3.7.12)
options (2.3.2)
pastel (0.7.2)
equatable (~> 0.5.0)
tty-color (~> 0.4.0)
pg (1.1.4)
pghero (2.2.0)
activerecord
progress_bar (1.3.0)
highline (>= 1.6, < 3)
options (~> 2.3.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.7.0)
byebug (~> 11.0)
pry (~> 0.10)
puma (3.12.1)
rack (2.0.6)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.3)
Expand Down Expand Up @@ -109,18 +155,65 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-sqlimit (0.0.2)
rails (> 4.0, < 6.0)
rspec (~> 3.0)
rspec-support (3.8.0)
ruby_dep (1.5.0)
skylight (3.1.5)
skylight-core (= 3.1.5)
skylight-core (3.1.5)
activesupport (>= 4.2.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
strings (0.1.5)
strings-ansi (~> 0.1)
unicode-display_width (~> 1.5)
unicode_utils (~> 1.4)
strings-ansi (0.1.0)
strong_migrations (0.3.1)
activerecord (>= 3.2.0)
test-prof (0.8.0)
thor (0.20.3)
thread_safe (0.3.6)
tty-color (0.4.3)
tty-pager (0.12.1)
strings (~> 0.1.4)
tty-screen (~> 0.6)
tty-which (~> 0.4)
tty-screen (0.6.5)
tty-tree (0.2.0)
tty-which (0.4.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.5.0)
unicode_utils (1.4.0)
uniform_notifier (1.12.1)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -134,12 +227,29 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord-import
bootsnap (>= 1.1.0)
bullet
byebug
database_cleaner
factory_bot_rails
faker!
listen (>= 3.0.5, < 3.2)
n_plus_one_control
newrelic_rpm
oj
pg (>= 0.18, < 2.0)
pghero
progress_bar
pry-byebug
puma (~> 3.11)
rails (~> 5.2.3)
rspec
rspec-rails
rspec-sqlimit
skylight
strong_migrations
test-prof
tzinfo-data
web-console (>= 3.3.0)

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

class TripsController < ApplicationController
def index
@from = City.find_by_name!(params[:from])
@to = City.find_by_name!(params[:to])
@trips = Trip.where(from: @from, to: @to).order(:start_time)
@trips = Trip.preload(bus: :services).where(from: @from, to: @to).order(:start_time)
end
end
27 changes: 15 additions & 12 deletions app/models/bus.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# frozen_string_literal: true

class Bus < ApplicationRecord
MODELS = [
'Икарус',
'Мерседес',
'Сканиа',
'Буханка',
'УАЗ',
'Спринтер',
'ГАЗ',
'ПАЗ',
'Вольво',
'Газель',
MODELS = %w[
Икарус
Мерседес
Сканиа
Буханка
УАЗ
Спринтер
ГАЗ
ПАЗ
Вольво
Газель
].freeze

has_many :trips
has_and_belongs_to_many :services, join_table: :buses_services
has_many :buses_services
has_many :services, through: :buses_services

validates :number, presence: true, uniqueness: true
validates :model, inclusion: { in: MODELS }
Expand Down
6 changes: 6 additions & 0 deletions app/models/buses_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class BusesService < ApplicationRecord
belongs_to :bus
belongs_to :service
end
27 changes: 15 additions & 12 deletions app/models/service.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# frozen_string_literal: true

class Service < ApplicationRecord
SERVICES = [
'WiFi',
'Туалет',
'Работающий туалет',
'Ремни безопасности',
'Кондиционер общий',
'Кондиционер Индивидуальный',
'Телевизор общий',
'Телевизор индивидуальный',
'Стюардесса',
'Можно не печатать билет',
SERVICES = %w[
WiFi
Туалет
Работающий туалет
Ремни безопасности
Кондиционер общий
Кондиционер Индивидуальный
Телевизор общий
Телевизор индивидуальный
Стюардесса
Можно не печатать билет
].freeze

has_and_belongs_to_many :buses, join_table: :buses_services
has_many :buses_services
has_many :buses, through: :buses_services

validates :name, presence: true
validates :name, inclusion: { in: SERVICES }
Expand Down
Loading