Commit b0ef03e5 authored by hellekin's avatar hellekin

Add Collection

Add resource_collection spec
parent a82d5681
......@@ -13,6 +13,16 @@ class Collection < ApplicationRecord
# Break the map, but do not destroy it: we might want to restore it with a new
# collection, in which case existing maps would still work.
has_many :maps, dependent: :nullify
validates :name,
presence: true,
uniqueness: { scope: :agent_id }
validates :summary,
length: { within: 0..160 },
allow_nil: true
validates :description,
length: { within: 0..8.kilobytes },
allow_nil: true
end
# == Schema Information
......
Fabricator(:collection) do
name "MyString"
summary "MyString"
description "MyText"
agent nil
name "The Commons Collection"
summary "This collection gathers resources from The Commons."
description { Faker::Markdown.sandwich(6, 3) }
agent
end
# == Schema Information
......
Fabricator(:resource_collection) do
resource nil
collection nil
resource
collection
end
# == Schema Information
......
require 'rails_helper'
RSpec.describe Collection, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
let(:collection) { Fabricate(:collection) }
describe 'factory' do
it 'exists and is valid' do
expect(collection).to be_valid
end
end
describe 'associations' do
it 'belongs to an Agent' do
expect(collection).to belong_to(:agent)
end
it 'has many ResourceCollections' do
expect(collection).to have_many(:resource_collections)
end
it 'has many Maps' do
expect(collection).to have_many(:maps)
end
end
describe 'validations' do
describe '#name' do
it 'must be present' do
collection.name= nil
expect(collection).not_to be_valid
end
it 'must be unique within the scope of its Agent' do
expect do
Fabricate(:collection,
name: collection.name,
agent: collection.agent)
end.to raise_error(ActiveRecord::RecordInvalid)
.with_message("Validation failed: Name has already been taken")
end
pending 'is translated'
end
describe '#summary' do
it 'is optional' do
collection.summary = nil
expect(collection).to be_valid
end
it 'is limited to 160 characters' do
collection.summary = 'a' * 160
expect(collection).to be_valid
collection.summary += 'b'
expect(collection).not_to be_valid
end
pending 'is translated'
end
describe '#description' do
it 'is optional' do
collection.description = nil
expect(collection).to be_valid
end
pending 'is Markdown'
pending 'is translated'
end
end
end
# == Schema Information
#
# Table name: collections
#
# id :bigint(8) not null, primary key
# translations :json
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :bigint(8)
#
# Indexes
#
# index_collections_on_agent_id (agent_id)
#
# == Schema Information
#
......
require 'rails_helper'
RSpec.describe ResourceCollection, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
let(:rcol) { Fabricate(:resource_collection) }
describe 'factory' do
it 'exists and is valid' do
expect(rcol).to be_valid
end
end
describe 'associations' do
it 'belongs to a Resource' do
expect(rcol).to belong_to(:resource)
end
it 'belongs to a Collection' do
expect(rcol).to belong_to(:collection)
end
end
describe 'validations' do
describe '#collection' do
it 'must be present' do
expect(rcol.collection).not_to be_nil
end
end
describe '#resource' do
it 'must be present' do
expect(rcol.resource).not_to be_nil
end
end
end
end
# == Schema Information
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment