Skip to content

Commit

Permalink
created db and low level stuff for characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedao committed Jun 4, 2023
1 parent 19d8025 commit 61bcc58
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class Campaign < ApplicationRecord

has_many :campaign_users
has_many :users, through: :campaign_users
has_many :characters
end
8 changes: 8 additions & 0 deletions app/models/character.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Character < ApplicationRecord
validates_presence_of :name

has_rich_text :background

belongs_to :user
belongs_to :campaign
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class User < ApplicationRecord

has_many :campaign_users
has_many :campaigns, through: :campaign_users
has_many :characters
end
12 changes: 12 additions & 0 deletions db/migrate/20230604195042_create_characters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateCharacters < ActiveRecord::Migration[7.0]
def change
create_table :characters do |t|
t.string :name
t.string :image_url
t.references :user, null: false, foreign_key: true
t.references :campaign, null: false, foreign_key: true

t.timestamps
end
end
end
15 changes: 14 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/models/campaign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
describe 'relationships' do
it { should have_many :campaign_users }
it { should have_many(:users).through(:campaign_users)}
it { should have_many :characters }
end
end
12 changes: 12 additions & 0 deletions spec/models/characters_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'

RSpec.describe Character, type: :model do
describe 'validations' do
it { should validate_presence_of :name }
end

describe 'relationships' do
it { should belong_to :campaign }
it { should belong_to :user }
end
end
1 change: 1 addition & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
describe 'relationships' do
it { should have_many :campaign_users }
it { should have_many(:campaigns).through(:campaign_users)}
it { should have_many :characters }
end
end

0 comments on commit 61bcc58

Please sign in to comment.