From ed7fd504cb14c8576421648e7bc68b421d2c413c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 1 Nov 2018 16:02:34 -0500 Subject: [PATCH] add Vehicle page type --- app/controllers/vehicles_controller.rb | 13 ++++++++ app/models/content_types/universe.rb | 1 + app/models/content_types/vehicle.rb | 31 ++++++++++++++++++++ config/attributes/vehicle.yml | 26 ++++++++++++++++ config/initializers/content_types.rb | 6 ++-- config/routes.rb | 3 ++ db/migrate/20181101205729_create_vehicles.rb | 14 +++++++++ db/schema.rb | 15 +++++++++- docs/content_types.md | 7 ++--- test/fixtures/vehicles.yml | 15 ++++++++++ test/models/vehicle_test.rb | 7 +++++ 11 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 app/controllers/vehicles_controller.rb create mode 100644 app/models/content_types/vehicle.rb create mode 100644 config/attributes/vehicle.yml create mode 100644 db/migrate/20181101205729_create_vehicles.rb create mode 100644 test/fixtures/vehicles.yml create mode 100644 test/models/vehicle_test.rb diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb new file mode 100644 index 00000000..4e7edd7c --- /dev/null +++ b/app/controllers/vehicles_controller.rb @@ -0,0 +1,13 @@ + +class VehiclesController < ContentController + private + + def content_param_list + [ + :name, :universe_id, :privacy + ] + [ # + + ] + end +end + \ No newline at end of file diff --git a/app/models/content_types/universe.rb b/app/models/content_types/universe.rb index e7f06055..0c297eb2 100644 --- a/app/models/content_types/universe.rb +++ b/app/models/content_types/universe.rb @@ -44,6 +44,7 @@ class Universe < ApplicationRecord has_many :scenes has_many :technologies has_many :towns + has_many :vehicles has_many :contributors, dependent: :destroy diff --git a/app/models/content_types/vehicle.rb b/app/models/content_types/vehicle.rb new file mode 100644 index 00000000..95ea14c5 --- /dev/null +++ b/app/models/content_types/vehicle.rb @@ -0,0 +1,31 @@ + +class Vehicle < ActiveRecord::Base + acts_as_paranoid + + belongs_to :user + validates :name, presence: true + validates :user_id, presence: true + + include BelongsToUniverse + include HasAttributes + include HasPrivacy + include HasContentGroupers + include HasImageUploads + include HasChangelog + include Serendipitous::Concern + + include Authority::Abilities + self.authorizer_name = 'ExtendedContentAuthorizer' + + def self.color + 'brown' + end + + def self.icon + 'info' + end + + def self.content_name + 'vehicle' + end +end diff --git a/config/attributes/vehicle.yml b/config/attributes/vehicle.yml new file mode 100644 index 00000000..c1926e6c --- /dev/null +++ b/config/attributes/vehicle.yml @@ -0,0 +1,26 @@ + +:overview: + :label: Overview + :icon: info + :attributes: + - :name: name + :label: Name + - :name: universe_id + :label: Universe + - :name: privacy + :label: Privacy +:gallery: + :label: Gallery + :icon: photo_library +:changelog: + :label: Changelog + :icon: history +:notes: + :label: Notes + :icon: edit + :attributes: + - :name: notes + :label: Notes + - :name: private_notes + :label: Private Notes + :description: Private notes are always visible to only you, even if content is made public and shared. diff --git a/config/initializers/content_types.rb b/config/initializers/content_types.rb index 1d64bb78..7865c440 100644 --- a/config/initializers/content_types.rb +++ b/config/initializers/content_types.rb @@ -3,7 +3,7 @@ Rails.application.config.content_types = { all: [ Universe, Character, Location, Item, Country, Creature, Deity, Flora, Government, Group, Landmark, Language, Magic, Planet, Race, Religion, Scene, - Technology, Town + Technology, Town, Vehicle ], # These content types are always on for all users, and cannot be toggled off @@ -15,7 +15,7 @@ Rails.application.config.content_types = { # These content types are available to be turned on available: [ Country, Creature, Deity, Flora, Government, Group, Landmark, Language, - Magic, Planet, Race, Religion, Scene, Technology, Town + Magic, Planet, Race, Religion, Scene, Technology, Town, Vehicle ], # These content types can be created by any user @@ -24,7 +24,7 @@ Rails.application.config.content_types = { # These content types require a premium subscription to create premium: [ Country, Creature, Deity, Flora, Government, Group, Landmark, Language, - Magic, Planet, Race, Religion, Scene, Technology, Town + Magic, Planet, Race, Religion, Scene, Technology, Town, Vehicle ] } diff --git a/config/routes.rb b/config/routes.rb index c0e409df..a6ac7e2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,6 +25,7 @@ Rails.application.routes.draw do get :technologies, on: :member get :deities, on: :member get :governments, on: :member + get :vehicles, on: :member # end @@ -120,6 +121,7 @@ Rails.application.routes.draw do get :technologies, on: :member get :deities, on: :member get :governments, on: :member + get :vehicles, on: :member # end resources :characters do @@ -146,6 +148,7 @@ Rails.application.routes.draw do resources :technologies resources :deities resources :governments + resources :vehicles # # Content attributes diff --git a/db/migrate/20181101205729_create_vehicles.rb b/db/migrate/20181101205729_create_vehicles.rb new file mode 100644 index 00000000..cee779f5 --- /dev/null +++ b/db/migrate/20181101205729_create_vehicles.rb @@ -0,0 +1,14 @@ +class CreateVehicles < ActiveRecord::Migration[5.2] + def change + create_table :vehicles do |t| + t.string :name + t.references :user, foreign_key: true + t.references :universe, foreign_key: true + t.datetime :deleted_at + t.string :privacy + t.string :page_type, default: 'Vehicle' + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 59ae690e..b516849f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_30_051214) do +ActiveRecord::Schema.define(version: 2018_11_01_205729) do create_table "api_keys", force: :cascade do |t| t.integer "user_id" @@ -2314,6 +2314,19 @@ ActiveRecord::Schema.define(version: 2018_10_30_051214) do t.index ["username"], name: "index_users_on_username", unique: true end + create_table "vehicles", force: :cascade do |t| + t.string "name" + t.integer "user_id" + t.integer "universe_id" + t.datetime "deleted_at" + t.string "privacy" + t.string "page_type", default: "Vehicle" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["universe_id"], name: "index_vehicles_on_universe_id" + t.index ["user_id"], name: "index_vehicles_on_user_id" + end + create_table "votables", force: :cascade do |t| t.string "name" t.string "description" diff --git a/docs/content_types.md b/docs/content_types.md index 75c41e97..21c3b46d 100644 --- a/docs/content_types.md +++ b/docs/content_types.md @@ -4,15 +4,14 @@ Checklist to create a new content type: - e.g. https://github.com/indentlabs/notebook/issues/258 - Generate models (with non-relation fields) - - rails g model Planet name:string description:string ... - - don't forget to add `privacy`, `notes`, `private_notes`, `user_id`, `universe_id`, `deleted_at` - - probably want to just put core attributes here eventually, after de-systemizing other fields + - `rails g model Planet name:string user:references universe:references deleted_at:datetime privacy:string` + - `rake db:migrate` - Run `rake page_type:create` and type "Planet" at the prompt - Edit app/models/content_types/planet.rb to define color and icon -- Add has_many :planets to universe.rb +- Add `has_many :planets` to universe.rb - Add the content class to initializers/content_types.rb - most likely to :all, :available, and :free/:premium diff --git a/test/fixtures/vehicles.yml b/test/fixtures/vehicles.yml new file mode 100644 index 00000000..d801e2bd --- /dev/null +++ b/test/fixtures/vehicles.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + user: one + universe: one + deleted_at: 2018-11-01 15:57:29 + privacy: MyString + +two: + name: MyString + user: two + universe: two + deleted_at: 2018-11-01 15:57:29 + privacy: MyString diff --git a/test/models/vehicle_test.rb b/test/models/vehicle_test.rb new file mode 100644 index 00000000..bfcbfff5 --- /dev/null +++ b/test/models/vehicle_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class VehicleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end