From 0185ac276c11e4c7b8c136da12f03a180bf405be Mon Sep 17 00:00:00 2001 From: bijan Date: Thu, 12 May 2022 19:44:54 +0430 Subject: [PATCH] add message model and migration --- app/admin/messages.rb | 22 ++++++++++++++++++++ app/models/message.rb | 2 ++ db/migrate/20220512140948_create_messages.rb | 11 ++++++++++ db/schema.rb | 11 +++++++++- db/seeds.rb | 6 ++++-- test/fixtures/messages.yml | 11 ++++++++++ test/models/message_test.rb | 7 +++++++ 7 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 app/models/message.rb create mode 100644 db/migrate/20220512140948_create_messages.rb create mode 100644 test/fixtures/messages.yml create mode 100644 test/models/message_test.rb diff --git a/app/admin/messages.rb b/app/admin/messages.rb index e69de29..2a4eb76 100644 --- a/app/admin/messages.rb +++ b/app/admin/messages.rb @@ -0,0 +1,22 @@ +ActiveAdmin.register Message do + csv do + column :title + column(:email) + column('bODY', humanize_name: false) # preserve case + end + # See permitted parameters documentation: + # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters + # + # Uncomment all parameters which should be permitted for assignment + # + permit_params :title, :description, :email, :phone + # + # or + # + # permit_params do + # permitted = [:title, :description, :email, :phone] + # permitted << :other if params[:action] == 'create' && current_user.admin? + # permitted + # end + +end diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 0000000..28bdd9d --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,2 @@ +class Message < ApplicationRecord +end diff --git a/db/migrate/20220512140948_create_messages.rb b/db/migrate/20220512140948_create_messages.rb new file mode 100644 index 0000000..1687188 --- /dev/null +++ b/db/migrate/20220512140948_create_messages.rb @@ -0,0 +1,11 @@ +class CreateMessages < ActiveRecord::Migration[6.0] + def change + create_table :messages do |t| + t.string :title + t.text :description + t.string :email, null: false + t.string :phone + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index dc51303..ad798d8 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: 2022_05_12_124755) do +ActiveRecord::Schema.define(version: 2022_05_12_140948) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace" @@ -38,4 +38,13 @@ ActiveRecord::Schema.define(version: 2022_05_12_124755) do t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true end + create_table "messages", force: :cascade do |t| + t.string "title" + t.text "description" + t.string "email", null: false + t.string "phone" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + end diff --git a/db/seeds.rb b/db/seeds.rb index db78bf5..24d9a35 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,5 +5,7 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) -AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development? -AdminUser.create!(email: 'bijan@example.com', password: '1234567890', password_confirmation: '1234567890') if Rails.env.development? \ No newline at end of file +if Rails.env.development? + AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') + AdminUser.create!(email: 'bijan@example.com', password: '1234567890', password_confirmation: '1234567890') +end diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml new file mode 100644 index 0000000..5181636 --- /dev/null +++ b/test/fixtures/messages.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/message_test.rb b/test/models/message_test.rb new file mode 100644 index 0000000..11e5db0 --- /dev/null +++ b/test/models/message_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MessageTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end