Introduce projects and accesses
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
class Access < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
end
|
||||
@@ -1,4 +1,5 @@
|
||||
class Bubble < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
|
||||
has_many :comments, dependent: :destroy
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class Project < ApplicationRecord
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to :account, default: -> { creator&.account }
|
||||
|
||||
has_many :accesses, dependent: :destroy
|
||||
end
|
||||
+5
-1
@@ -7,6 +7,9 @@ class User < ApplicationRecord
|
||||
has_many :sessions, dependent: :destroy
|
||||
has_secure_password validations: false
|
||||
|
||||
has_many :accesses, dependent: :destroy
|
||||
has_many :projects, through: :accesses
|
||||
|
||||
normalizes :email_address, with: ->(value) { value.strip.downcase }
|
||||
|
||||
def initials
|
||||
@@ -15,7 +18,8 @@ class User < ApplicationRecord
|
||||
|
||||
def deactivate
|
||||
transaction do
|
||||
sessions.delete_all
|
||||
sessions.destroy_all
|
||||
accesses.destroy_all
|
||||
update! active: false, email_address: deactived_email_address
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateProjects < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :projects do |t|
|
||||
t.references :account, null: false
|
||||
t.references :creator, null: false
|
||||
t.string :name, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
Project.create!(name: "Writebook", creator: User.first)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class CreateAccesses < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :accesses do |t|
|
||||
t.references :project, null: false
|
||||
t.references :user, null: false
|
||||
t.timestamps
|
||||
|
||||
t.index [ :project_id, :user_id ], unique: true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class AddProjectToBubbles < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
change_table :bubbles do |t|
|
||||
t.references :project, null: true
|
||||
end
|
||||
|
||||
Bubble.update_all project_id: Project.first.id
|
||||
change_column_null :bubbles, :project_id, false
|
||||
end
|
||||
end
|
||||
Generated
+23
@@ -11,6 +11,17 @@
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2024_09_17_174301) do
|
||||
create_table "accesses", force: :cascade do |t|
|
||||
t.integer "project_id", null: false
|
||||
t.integer "user_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["project_id", "user_id"], name: "index_accesses_on_project_id_and_user_id", unique: true
|
||||
t.index ["project_id"], name: "index_accesses_on_project_id"
|
||||
t.index ["user_id"], name: "index_accesses_on_user_id"
|
||||
end
|
||||
|
||||
>>>>>>> d17053b (Introduce projects and accesses)
|
||||
create_table "accounts", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
@@ -72,6 +83,8 @@ ActiveRecord::Schema[8.0].define(version: 2024_09_17_174301) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "creator_id", null: false
|
||||
t.date "due_on"
|
||||
t.integer "project_id", null: false
|
||||
t.index ["project_id"], name: "index_bubbles_on_project_id"
|
||||
end
|
||||
|
||||
create_table "comments", force: :cascade do |t|
|
||||
@@ -82,6 +95,16 @@ ActiveRecord::Schema[8.0].define(version: 2024_09_17_174301) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "projects", force: :cascade do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.integer "creator_id", null: false
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_projects_on_account_id"
|
||||
t.index ["creator_id"], name: "index_projects_on_creator_id"
|
||||
end
|
||||
|
||||
create_table "sessions", force: :cascade do |t|
|
||||
t.integer "user_id", null: false
|
||||
t.string "ip_address"
|
||||
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
writebook_david:
|
||||
project: writebook
|
||||
user: david
|
||||
|
||||
writebook_jz:
|
||||
project: writebook
|
||||
user: jz
|
||||
|
||||
writebook_kevin:
|
||||
project: writebook
|
||||
user: kevin
|
||||
Vendored
+11
-9
@@ -1,20 +1,22 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
logo:
|
||||
project: writebook
|
||||
creator: david
|
||||
title: The logo isn't big enough
|
||||
body: Make the logo bigger.
|
||||
color: '#ED8008'
|
||||
creator: :david
|
||||
due_on: <%= 3.days.from_now %>
|
||||
|
||||
two:
|
||||
layout:
|
||||
project: writebook
|
||||
creator: david
|
||||
creator: jz
|
||||
title: Layout is broken
|
||||
body: The page scrolls horizontally on mobile devices.
|
||||
color: '#698F9C'
|
||||
creator: :david
|
||||
|
||||
three:
|
||||
text:
|
||||
project: writebook
|
||||
creator: kevin
|
||||
title: The text is too small
|
||||
body: Increase the font size.
|
||||
color: '#3B4B59'
|
||||
creator: :kevin
|
||||
color: "#3B4B59"
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
writebook:
|
||||
name: Writebook
|
||||
account: 37signals
|
||||
creator: david
|
||||
Vendored
+4
-6
@@ -1,17 +1,15 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
bubble: one
|
||||
bubble: logo
|
||||
tag: one
|
||||
|
||||
two:
|
||||
bubble: two
|
||||
bubble: layout
|
||||
tag: two
|
||||
|
||||
three:
|
||||
bubble: three
|
||||
bubble: layout
|
||||
tag: one
|
||||
|
||||
four:
|
||||
bubble: three
|
||||
bubble: text
|
||||
tag: two
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class AccessTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class ProjectTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user