Skip to content

Commit 0945839

Browse files
authored
Merge pull request #154 from SINDAN/feature/map
地図情報機能追加
2 parents 4578aef + 7651ab1 commit 0945839

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

app/models/map_image.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class MapImage < ApplicationRecord
2+
validates_uniqueness_of :name, allow_blank: true
3+
4+
default_scope { order(name: :asc) }
5+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateMapImages < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :map_images do |t|
4+
t.string :name
5+
t.string :file
6+
t.text :remarks
7+
8+
t.timestamps null: false
9+
end
10+
add_index :map_images, :name, unique: true
11+
end
12+
end

db/schema.rb

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories/map_images.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FactoryBot.define do
2+
factory :map_image do
3+
name { "Map Name" }
4+
file { "MyString" }
5+
remarks { "MyText" }
6+
end
7+
end

spec/models/map_image_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe MapImage, type: :model do
4+
before(:each) do
5+
@map_image = FactoryBot.build(:map_image, name: "Map Name")
6+
end
7+
8+
it "is valid with valid attributes" do
9+
expect(@map_image).to be_valid
10+
end
11+
12+
it "is not valid with same another name" do
13+
@map_image.save
14+
15+
@map_image_dup = FactoryBot.build(:map_image, name: "Map Name")
16+
17+
expect(@map_image_dup).not_to be_valid
18+
end
19+
20+
it "is valid with empty name" do
21+
@map_image.name = ''
22+
@map_image.save
23+
24+
@map_image_dup = FactoryBot.build(:map_image, name: "")
25+
26+
expect(@map_image_dup).to be_valid
27+
end
28+
end

0 commit comments

Comments
 (0)