diff --git a/lecture_1/homework/Gemfile b/lecture_1/homework/Gemfile index ea8c8818..36c9ebf9 100644 --- a/lecture_1/homework/Gemfile +++ b/lecture_1/homework/Gemfile @@ -1,12 +1,14 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.4.0' +ruby '2.5.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.2.2' # Use sqlite3 as the database for Active Record -gem 'sqlite3' +gem 'sqlite3', '~> 1.3.6' # Use Puma as the app server gem 'puma', '~> 3.11' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder @@ -30,7 +32,7 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'byebug', platforms: %i[mri mingw x64_mingw] end group :development do @@ -40,6 +42,11 @@ group :development do gem 'spring-watcher-listen', '~> 2.0.0' end - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] + +# faker +gem 'faker' + +# rubocop +# gem 'rubocop', require: false diff --git a/lecture_1/homework/Gemfile.lock b/lecture_1/homework/Gemfile.lock index 27a5c17f..e43a063f 100644 --- a/lecture_1/homework/Gemfile.lock +++ b/lecture_1/homework/Gemfile.lock @@ -50,6 +50,8 @@ GEM concurrent-ruby (1.1.5) crass (1.0.4) erubi (1.8.0) + faker (1.9.3) + i18n (>= 0.7) ffi (1.10.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -120,7 +122,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.4.0) + sqlite3 (1.3.13) thor (0.20.3) thread_safe (0.3.6) tzinfo (1.2.5) @@ -135,16 +137,17 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.1.0) byebug + faker listen (>= 3.0.5, < 3.2) puma (~> 3.11) rails (~> 5.2.2) spring spring-watcher-listen (~> 2.0.0) - sqlite3 + sqlite3 (~> 1.3.6) tzinfo-data RUBY VERSION - ruby 2.4.0p0 + ruby 2.5.1p57 BUNDLED WITH 2.0.1 diff --git a/lecture_1/homework/Rakefile b/lecture_1/homework/Rakefile index e85f9139..488c551f 100644 --- a/lecture_1/homework/Rakefile +++ b/lecture_1/homework/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/lecture_1/homework/app/channels/application_cable/channel.rb b/lecture_1/homework/app/channels/application_cable/channel.rb index d6726972..9aec2305 100644 --- a/lecture_1/homework/app/channels/application_cable/channel.rb +++ b/lecture_1/homework/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/lecture_1/homework/app/channels/application_cable/connection.rb b/lecture_1/homework/app/channels/application_cable/connection.rb index 0ff5442f..8d6c2a1b 100644 --- a/lecture_1/homework/app/channels/application_cable/connection.rb +++ b/lecture_1/homework/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/lecture_1/homework/app/controllers/application_controller.rb b/lecture_1/homework/app/controllers/application_controller.rb index 4ac8823b..13c271fb 100644 --- a/lecture_1/homework/app/controllers/application_controller.rb +++ b/lecture_1/homework/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::API end diff --git a/lecture_1/homework/app/controllers/clans_controller.rb b/lecture_1/homework/app/controllers/clans_controller.rb new file mode 100644 index 00000000..e47561be --- /dev/null +++ b/lecture_1/homework/app/controllers/clans_controller.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class ClansController < ApplicationController + def index + clans = Clan.all + render json: clans.to_json, status: 200 + end + + def show + render json: clan.to_json, status: 200 + end + + def create + clan = Clan.create!(clan_params) + render json: clan.to_json, status: 201 + rescue ActiveRecord::ActiveRecordError => e + render json: e.to_json, status: 422 + end + + def update + clan.update!(orc_params) + render json: clan.to_json, status: 201 + rescue ActiveRecord::ActiveRecordError => e + render json: e.to_json, status: 422 + end + + def destroy + clan.destroy! + head 204 + rescue ActiveRecord::ActiveRecordError => e + render json: e.to_json, status: 404 + end + + private + + def clan + @clan ||= Clan.find(clan_params[:id]) + end + + def clan_params + params.permit(:name) + end +end + diff --git a/lecture_1/homework/app/controllers/samurais_controller.rb b/lecture_1/homework/app/controllers/samurais_controller.rb new file mode 100644 index 00000000..323dbdbf --- /dev/null +++ b/lecture_1/homework/app/controllers/samurais_controller.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +class SamuraisController < ApplicationController + def index + samurais = clan.samurais.all + if params.key?(:alive) + if params[:alive].to_i.zero? + render json: samurais.dead, include: %w[clan], + status: 200 + else + render json: samurais.alive, include: %w[clan], + status: 200 + end + else + render json: samurais, include: %w[clan], status: 200 + end + end + + def show + render json: samurai.to_json, status: 200 + end + + def destroy + samurai.destroy! + head 204 + rescue ActiveRecord::ActiveRecordError => e + render json: e.to_json, status: 404 + end + + def create + samurai = clan.samurais.create!(samurai_params) + render json: samurai.to_json, status: 201 + rescue ActiveRecord::ActiveRecordError => e + render json: e.to_json, status: 422 + end + + def update + samurai.update!(samurai_params) + render json: samurai.to_json, status: 201 + rescue ActiveRecord::ActiveRecordError => e + render json: e.to_json, status: 422 + end + + private + + def samurai + @samurai ||= clan.samurais.find(params[:id]) + end + + def clan + @clan ||= Clan.find(params[:clan_id]) + end + + def samurai_params + params.permit(:name, :armour_rating, :battle_count, :join_date, :death_date) + end +end diff --git a/lecture_1/homework/app/jobs/application_job.rb b/lecture_1/homework/app/jobs/application_job.rb index a009ace5..d92ffddc 100644 --- a/lecture_1/homework/app/jobs/application_job.rb +++ b/lecture_1/homework/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/lecture_1/homework/app/mailers/application_mailer.rb b/lecture_1/homework/app/mailers/application_mailer.rb index 286b2239..d84cb6e7 100644 --- a/lecture_1/homework/app/mailers/application_mailer.rb +++ b/lecture_1/homework/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/lecture_1/homework/app/models/application_record.rb b/lecture_1/homework/app/models/application_record.rb index 10a4cba8..71fbba5b 100644 --- a/lecture_1/homework/app/models/application_record.rb +++ b/lecture_1/homework/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/lecture_1/homework/app/models/clan.rb b/lecture_1/homework/app/models/clan.rb new file mode 100644 index 00000000..0b79900a --- /dev/null +++ b/lecture_1/homework/app/models/clan.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Clan < ApplicationRecord + has_many :samurais, dependent: :destroy + + validates name, presence: true +end diff --git a/lecture_1/homework/app/models/samurai.rb b/lecture_1/homework/app/models/samurai.rb new file mode 100644 index 00000000..bdf7e959 --- /dev/null +++ b/lecture_1/homework/app/models/samurai.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Samurai < ApplicationRecord + belongs_to :clan + validates name, presence: true + validates armour_rating, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 } + validates battle_count, presence: true + validates join_date, presence: true + # validates death_date + scope :alive, -> { where('death_date IS NULL') } + scope :dead, -> { where('death_date IS NOT NULL') } +end diff --git a/lecture_1/homework/bin/bundle b/lecture_1/homework/bin/bundle index f19acf5b..2dbb7176 100755 --- a/lecture_1/homework/bin/bundle +++ b/lecture_1/homework/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/lecture_1/homework/bin/rails b/lecture_1/homework/bin/rails index 5badb2fd..3504c3f9 100755 --- a/lecture_1/homework/bin/rails +++ b/lecture_1/homework/bin/rails @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/lecture_1/homework/bin/rake b/lecture_1/homework/bin/rake index d87d5f57..1fe6cf06 100755 --- a/lecture_1/homework/bin/rake +++ b/lecture_1/homework/bin/rake @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/lecture_1/homework/bin/setup b/lecture_1/homework/bin/setup index a334d86a..f17c5668 100755 --- a/lecture_1/homework/bin/setup +++ b/lecture_1/homework/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' include FileUtils diff --git a/lecture_1/homework/bin/spring b/lecture_1/homework/bin/spring index fb2ec2eb..9bd27ec6 100755 --- a/lecture_1/homework/bin/spring +++ b/lecture_1/homework/bin/spring @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. @@ -8,7 +9,7 @@ unless defined?(Spring) require 'bundler' lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == "spring" } + spring = lockfile.specs.detect { |spec| spec.name == 'spring' } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version diff --git a/lecture_1/homework/bin/update b/lecture_1/homework/bin/update index 67d0d496..0b5306f4 100755 --- a/lecture_1/homework/bin/update +++ b/lecture_1/homework/bin/update @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' include FileUtils diff --git a/lecture_1/homework/config.ru b/lecture_1/homework/config.ru index f7ba0b52..842bccc3 100644 --- a/lecture_1/homework/config.ru +++ b/lecture_1/homework/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/lecture_1/homework/config/application.rb b/lecture_1/homework/config/application.rb index f5390e33..02acf880 100644 --- a/lecture_1/homework/config/application.rb +++ b/lecture_1/homework/config/application.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require_relative 'boot' -require "rails" +require 'rails' # Pick the frameworks you want: -require "active_model/railtie" -require "active_job/railtie" -require "active_record/railtie" -require "active_storage/engine" -require "action_controller/railtie" -require "action_mailer/railtie" -require "action_view/railtie" -require "action_cable/engine" +require 'active_model/railtie' +require 'active_job/railtie' +require 'active_record/railtie' +require 'active_storage/engine' +require 'action_controller/railtie' +require 'action_mailer/railtie' +require 'action_view/railtie' +require 'action_cable/engine' # require "sprockets/railtie" -require "rails/test_unit/railtie" +require 'rails/test_unit/railtie' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/lecture_1/homework/config/boot.rb b/lecture_1/homework/config/boot.rb index b9e460ce..c04863fa 100644 --- a/lecture_1/homework/config/boot.rb +++ b/lecture_1/homework/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/lecture_1/homework/config/environment.rb b/lecture_1/homework/config/environment.rb index 426333bb..d5abe558 100644 --- a/lecture_1/homework/config/environment.rb +++ b/lecture_1/homework/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/lecture_1/homework/config/environments/development.rb b/lecture_1/homework/config/environments/development.rb index d52ec9ef..b6c18169 100644 --- a/lecture_1/homework/config/environments/development.rb +++ b/lecture_1/homework/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -44,7 +46,6 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/lecture_1/homework/config/environments/production.rb b/lecture_1/homework/config/environments/production.rb index 77930568..7be304fb 100644 --- a/lecture_1/homework/config/environments/production.rb +++ b/lecture_1/homework/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -45,7 +47,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -74,7 +76,7 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/lecture_1/homework/config/environments/test.rb b/lecture_1/homework/config/environments/test.rb index 0a38fd3c..3091ac4b 100644 --- a/lecture_1/homework/config/environments/test.rb +++ b/lecture_1/homework/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/lecture_1/homework/config/initializers/application_controller_renderer.rb b/lecture_1/homework/config/initializers/application_controller_renderer.rb index 89d2efab..6d56e439 100644 --- a/lecture_1/homework/config/initializers/application_controller_renderer.rb +++ b/lecture_1/homework/config/initializers/application_controller_renderer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/lecture_1/homework/config/initializers/backtrace_silencers.rb b/lecture_1/homework/config/initializers/backtrace_silencers.rb index 59385cdf..4b63f289 100644 --- a/lecture_1/homework/config/initializers/backtrace_silencers.rb +++ b/lecture_1/homework/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/lecture_1/homework/config/initializers/cors.rb b/lecture_1/homework/config/initializers/cors.rb index 3b1c1b5e..82eafe5c 100644 --- a/lecture_1/homework/config/initializers/cors.rb +++ b/lecture_1/homework/config/initializers/cors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Avoid CORS issues when API is called from the frontend app. diff --git a/lecture_1/homework/config/initializers/filter_parameter_logging.rb b/lecture_1/homework/config/initializers/filter_parameter_logging.rb index 4a994e1e..7a4f47b4 100644 --- a/lecture_1/homework/config/initializers/filter_parameter_logging.rb +++ b/lecture_1/homework/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/lecture_1/homework/config/initializers/inflections.rb b/lecture_1/homework/config/initializers/inflections.rb index ac033bf9..dc847422 100644 --- a/lecture_1/homework/config/initializers/inflections.rb +++ b/lecture_1/homework/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/lecture_1/homework/config/initializers/mime_types.rb b/lecture_1/homework/config/initializers/mime_types.rb index dc189968..be6fedc5 100644 --- a/lecture_1/homework/config/initializers/mime_types.rb +++ b/lecture_1/homework/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/lecture_1/homework/config/initializers/wrap_parameters.rb b/lecture_1/homework/config/initializers/wrap_parameters.rb index bbfc3961..2f3c0db4 100644 --- a/lecture_1/homework/config/initializers/wrap_parameters.rb +++ b/lecture_1/homework/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/lecture_1/homework/config/puma.rb b/lecture_1/homework/config/puma.rb index a5eccf81..940c8ba4 100644 --- a/lecture_1/homework/config/puma.rb +++ b/lecture_1/homework/config/puma.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/lecture_1/homework/config/routes.rb b/lecture_1/homework/config/routes.rb index 787824f8..5cd5bc24 100644 --- a/lecture_1/homework/config/routes.rb +++ b/lecture_1/homework/config/routes.rb @@ -1,3 +1,12 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html -end + get 'samurais/index' + get 'clans/index' + resources :clans, only: %i[index create show update destroy] do + resources :samurais, module: :clans do + resources :alive, only: %i[index] + resources :dead, only: %i[index] + end + end +end \ No newline at end of file diff --git a/lecture_1/homework/config/spring.rb b/lecture_1/homework/config/spring.rb index 9fa7863f..c5933e49 100644 --- a/lecture_1/homework/config/spring.rb +++ b/lecture_1/homework/config/spring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + %w[ .ruby-version .rbenv-vars diff --git a/lecture_1/homework/db/migrate/20190319154846_create_clans.rb b/lecture_1/homework/db/migrate/20190319154846_create_clans.rb new file mode 100644 index 00000000..9794919a --- /dev/null +++ b/lecture_1/homework/db/migrate/20190319154846_create_clans.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class CreateClans < ActiveRecord::Migration[5.2] + def change + create_table :clans do |t| + t.string :name + t.timestamps + end + end +end diff --git a/lecture_1/homework/db/migrate/20190319154851_create_samurais.rb b/lecture_1/homework/db/migrate/20190319154851_create_samurais.rb new file mode 100644 index 00000000..7cea0e21 --- /dev/null +++ b/lecture_1/homework/db/migrate/20190319154851_create_samurais.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class CreateSamurais < ActiveRecord::Migration[5.2] + def change + create_table :samurais do |t| + t.references :clan, foreign_key: true + t.string :name + t.integer :armour_rating + t.integer :battle_count + t.date :join_date + t.date :death_date, null: true + t.timestamps + end + end +end diff --git a/lecture_1/homework/db/schema.rb b/lecture_1/homework/db/schema.rb new file mode 100644 index 00000000..e1c11865 --- /dev/null +++ b/lecture_1/homework/db/schema.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20_190_319_154_851) do + create_table 'clans', force: :cascade do |t| + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + end + + create_table 'samurais', force: :cascade do |t| + t.integer 'clan_id' + t.string 'name' + t.integer 'armour_rating' + t.integer 'battle_count' + t.date 'join_date' + t.date 'death_date' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['clan_id'], name: 'index_samurais_on_clan_id' + end +end diff --git a/lecture_1/homework/db/seeds.rb b/lecture_1/homework/db/seeds.rb index 1beea2ac..5e8af819 100644 --- a/lecture_1/homework/db/seeds.rb +++ b/lecture_1/homework/db/seeds.rb @@ -1,7 +1,38 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). -# -# Examples: -# -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) +# frozen_string_literal: true + +require 'faker' + +clan1 = Clan.create!(name: Faker::Creature::Cat.unique.registry) +clan2 = Clan.create!(name: Faker::Creature::Cat.unique.registry) +samurai1 = Samurai.create!( + name: Faker::Creature::Cat.unique.name, + armour_rating: Faker::Number.between(0, 1000), + battle_count: Faker::Number.between(0, 200), + join_date: Faker::Date.birthday(20, 70), + death_date: Faker::Date.backward(20), + clan: clan1 +) +samurai2 = Samurai.create!( + name: Faker::Creature::Cat.unique.name, + armour_rating: Faker::Number.between(0, 1000), + battle_count: Faker::Number.between(0, 200), + join_date: Faker::Date.birthday(20, 70), + death_date: Faker::Date.backward(20), + clan: clan1 +) +samurai3 = Samurai.create!( + name: Faker::Creature::Cat.unique.name, + armour_rating: Faker::Number.between(0, 1000), + battle_count: Faker::Number.between(0, 200), + join_date: Faker::Date.birthday(20, 70), + death_date: Faker::Date.backward(20), + clan: clan2 +) +samurai4 = Samurai.create!( + name: Faker::Creature::Cat.unique.name, + armour_rating: Faker::Number.between(0, 1000), + battle_count: Faker::Number.between(0, 200), + join_date: Faker::Date.birthday(20, 70), + death_date: Faker::Date.backward(20), + clan: clan2 +) diff --git a/lecture_1/homework/test/controllers/.keep b/lecture_1/homework/test/controllers/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lecture_1/homework/test/fixtures/.keep b/lecture_1/homework/test/fixtures/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lecture_1/homework/test/fixtures/files/.keep b/lecture_1/homework/test/fixtures/files/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lecture_1/homework/test/integration/.keep b/lecture_1/homework/test/integration/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lecture_1/homework/test/mailers/.keep b/lecture_1/homework/test/mailers/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lecture_1/homework/test/models/.keep b/lecture_1/homework/test/models/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lecture_1/homework/test/test_helper.rb b/lecture_1/homework/test/test_helper.rb deleted file mode 100644 index 3ab84e3d..00000000 --- a/lecture_1/homework/test/test_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -ENV['RAILS_ENV'] ||= 'test' -require_relative '../config/environment' -require 'rails/test_help' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end