Skip to content

Commit

Permalink
Attributes stub.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Dec 4, 2013
1 parent e477b43 commit 78b5503
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Attribute < ActiveRecord::Base
belongs_to :attribute_subject, polymorphic: true
validates :attribute_subject, presence: true
validates_presence_of :type, :value
end
3 changes: 3 additions & 0 deletions app/models/attribute/import.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Attribute::Import < Attribute
validates_presence_of :import_predicate
end
4 changes: 4 additions & 0 deletions app/models/attribute/internal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Attribute::Internal < Attribute
belongs_to :predicate, foreign_key: :controlled_vocabulary_term_id
validates :predicate, presence: true
end
2 changes: 2 additions & 0 deletions app/models/controlled_vocabulary_term/predicate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ControlledVocabularyTerm::Predicate < ActiveRecord::Base
end
14 changes: 14 additions & 0 deletions db/migrate/20131203212239_create_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateAttributes < ActiveRecord::Migration
def change
create_table :attributes do |t|
t.string :type
t.integer :attribute_subject_id
t.string :attribute_subject_type
t.integer :controlled_vocabularly_term_id
t.string :import_predicate
t.string :value

t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions spec/factories/attribute_imports.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :attribute_import, :class => 'Attribute::Import' do
end
end
6 changes: 6 additions & 0 deletions spec/factories/attribute_internals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :attribute_internal, :class => 'Attribute::Internal' do
end
end
12 changes: 12 additions & 0 deletions spec/factories/attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :attribute do
type ""
attribute_subject_id 1
attribute_subject_type "MyString"
controlled_vocabularly_term_id 1
import_predicate "MyString"
value "MyString"
end
end
6 changes: 6 additions & 0 deletions spec/factories/controlled_vocabulary_term_predicates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :controlled_vocabulary_term_predicate, :class => 'ControlledVocabularyTerm::Predicate' do
end
end
17 changes: 17 additions & 0 deletions spec/models/attribute/import_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe Attribute::Import do
let (:attribute) {Attribute::Import.new}

context 'validation' do
before(:each) {
attribute.valid?
}
context 'requires' do
specify 'import_predicate' do
expect(attribute.errors.include?(:import_predicate)).to be_true
end
end
end

end
16 changes: 16 additions & 0 deletions spec/models/attribute/internal_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Attribute::Internal do
let (:attribute) {Attribute::Internal.new}

context 'validation' do
before(:each) {
attribute.valid?
}
context 'requires' do
specify 'predicate' do
expect(attribute.errors.include?(:predicate)).to be_true
end
end
end
end
24 changes: 24 additions & 0 deletions spec/models/attribute_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe Attribute do
let (:attribute) {Attribute.new}

context 'validation' do
before(:each) {
attribute.valid?
}
context 'requires' do
specify 'attribute_subject' do
expect(attribute.errors.include?(:attribute_subject)).to be_true
end

specify 'value' do
expect(attribute.errors.include?(:value)).to be_true
end

specify 'type' do
expect(attribute.errors.include?(:type)).to be_true
end
end
end
end
5 changes: 5 additions & 0 deletions spec/models/controlled_vocabulary_term/predicate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe ControlledVocabularyTerm::Predicate do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 78b5503

Please sign in to comment.