-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add items and display them in the surroundings.
- Loading branch information
1 parent
668b48f
commit efc0002
Showing
15 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Item < ApplicationRecord | ||
MINIMUM_NAME_LENGTH = 3 | ||
MAXIMUM_NAME_LENGTH = 24 | ||
|
||
belongs_to :owner, polymorphic: true, optional: true | ||
|
||
validates :name, presence: true, | ||
length: { in: MINIMUM_NAME_LENGTH..MAXIMUM_NAME_LENGTH } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%# locals: (item:) %> | ||
<li id="surrounding_item_<%= item.id %>"> | ||
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="> | ||
<%= item.name %> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateItems < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :items do |t| | ||
t.references :owner, null: false, polymorphic: true | ||
|
||
t.string :name, null: false, limit: 24 | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :item do | ||
name | ||
|
||
trait :room do | ||
owner { association(:room) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe Item do | ||
describe "associations" do | ||
subject(:item) { create(:item, :room) } | ||
|
||
it { is_expected.to belong_to(:owner).optional(true) } | ||
end | ||
|
||
describe "validations" do | ||
subject(:item) { create(:item, :room) } | ||
|
||
it { is_expected.to validate_presence_of(:name) } | ||
|
||
it do | ||
expect(item).to validate_length_of(:name) | ||
.is_at_least(described_class::MINIMUM_NAME_LENGTH) | ||
.is_at_most(described_class::MAXIMUM_NAME_LENGTH) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe "game/surroundings/_item.html.erb" do | ||
subject(:html) do | ||
render template: "game/surroundings/_item", | ||
locals: { item: item } | ||
|
||
rendered | ||
end | ||
|
||
let(:item) { build_stubbed(:item) } | ||
|
||
it "renders the surrounding item" do | ||
expect(html).to have_css("#surrounding_item_#{item.id}", text: item.name) | ||
end | ||
end |