diff --git a/app/controllers/admin/currencies_controller.rb b/app/controllers/admin/currencies_controller.rb new file mode 100644 index 0000000..95f67c7 --- /dev/null +++ b/app/controllers/admin/currencies_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true +module Admin + class CurrenciesController < Admin::ApplicationController + end +end diff --git a/app/dashboards/currency_dashboard.rb b/app/dashboards/currency_dashboard.rb new file mode 100644 index 0000000..9364ffa --- /dev/null +++ b/app/dashboards/currency_dashboard.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true +require "administrate/base_dashboard" + +class CurrencyDashboard < Administrate::BaseDashboard + # ATTRIBUTE_TYPES + # a hash that describes the type of each of the model's fields. + # + # Each different type represents an Administrate::Field object, + # which determines how the attribute is displayed + # on pages throughout the dashboard. + ATTRIBUTE_TYPES = { + id: Field::Number, + name: Field::String, + created_at: Field::DateTime, + updated_at: Field::DateTime, + }.freeze + + # COLLECTION_ATTRIBUTES + # an array of attributes that will be displayed on the model's index page. + # + # By default, it's limited to four items to reduce clutter on index pages. + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = [:id, :name, :created_at, :updated_at].freeze + + # SHOW_PAGE_ATTRIBUTES + # an array of attributes that will be displayed on the model's show page. + SHOW_PAGE_ATTRIBUTES = [:id, :name, :created_at, :updated_at].freeze + + # FORM_ATTRIBUTES + # an array of attributes that will be displayed + # on the model's form (`new` and `edit`) pages. + FORM_ATTRIBUTES = [:name].freeze + + # COLLECTION_FILTERS + # a hash that defines filters that can be used while searching via the search + # field of the dashboard. + # + # For example to add an option to search for open resources by typing "open:" + # in the search field: + # + # COLLECTION_FILTERS = { + # open: ->(resources) { resources.where(open: true) } + # }.freeze + COLLECTION_FILTERS = {}.freeze + + # Overwrite this method to customize how currencies are displayed + # across all pages of the admin dashboard. + # + # def display_resource(currency) + # "Currency ##{currency.id}" + # end +end diff --git a/app/models/currency.rb b/app/models/currency.rb new file mode 100644 index 0000000..1b32a3a --- /dev/null +++ b/app/models/currency.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: currencies +# +# id :bigint not null, primary key +# name :string not null +# created_at :datetime not null +# updated_at :datetime not null +# +class Currency < ApplicationRecord + validates :name, presence: true +end diff --git a/config/routes.rb b/config/routes.rb index 4fcf6a4..5eaa02c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ Rails.application.routes.draw do namespace :admin do resources :users resources :user_documents + resources :currencies resources :admin_users root to: "users#index" diff --git a/db/migrate/20210811014107_create_currencies.rb b/db/migrate/20210811014107_create_currencies.rb new file mode 100644 index 0000000..78d5c83 --- /dev/null +++ b/db/migrate/20210811014107_create_currencies.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true +class CreateCurrencies < ActiveRecord::Migration[6.1] + def change + create_table(:currencies) do |t| + t.string(:name, null: false) + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index aba024e..8d91afe 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: 2021_08_08_153626) do +ActiveRecord::Schema.define(version: 2021_08_11_014107) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -55,6 +55,12 @@ ActiveRecord::Schema.define(version: 2021_08_08_153626) do t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true end + create_table "currencies", force: :cascade do |t| + t.string "name", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "user_documents", force: :cascade do |t| t.string "status", null: false t.bigint "user_id", null: false diff --git a/spec/models/currency_spec.rb b/spec/models/currency_spec.rb new file mode 100644 index 0000000..85691fd --- /dev/null +++ b/spec/models/currency_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: currencies +# +# id :bigint not null, primary key +# name :string not null +# created_at :datetime not null +# updated_at :datetime not null +# +require "rails_helper" + +RSpec.describe(Currency, type: :model) do + describe "validations" do + it { is_expected.to(validate_presence_of(:name)) } + end +end