Skip to content

Commit 95e9723

Browse files
committed
tests for basic (string) and has_many fields
1 parent 42563ab commit 95e9723

File tree

6 files changed

+58
-6
lines changed

6 files changed

+58
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## Version 0.8.0 2017-02-10
1+
## Version 0.8.0 2017-03-23
22

3+
* [fixed] fix incorrect url for file field when no value was stored
4+
* [changed] preserve order of has_many field values - closes #9
35
* [added] Rspec setup
46
* [added] add feature allowing model elements creation using website forms
57

kms_models.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
99
s.version = Kms::Models::VERSION
1010
s.authors = ["Igor Petrov"]
1111
s.email = ["[email protected]"]
12-
s.homepage = "http://webgradus.ru"
12+
s.homepage = "https://github.com/webgradus/kms_models"
1313
s.summary = "Extension for KMS"
1414
s.description = "KMS Models allows to define custom models on-the-fly."
1515
s.license = "MIT"

spec/factories/fields.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
name 'Name'
44
liquor_name 'name'
55
type Kms::StringField.name
6+
factory :has_many_field do
7+
type Kms::HasManyField.name
8+
name 'Comments'
9+
liquor_name 'comments'
10+
class_name { FactoryGirl.create(:associated_model).id }
11+
end
612
end
713
end

spec/factories/models.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
kms_model_name 'Posts'
44
collection_name 'posts'
55
label_field 'name'
6-
after(:create) do |model, evaluator|
7-
create_list(:field, 1, model: model)
6+
factory :model_with_string_field do
7+
after(:create) do |model, evaluator|
8+
create_list(:field, 1, model: model)
9+
end
10+
factory :model_allowing_creation do
11+
allow_creation_using_form true
12+
end
13+
14+
factory :associated_model do
15+
kms_model_name 'Comments'
16+
collection_name 'comments'
17+
end
818
end
9-
factory :model_allowing_creation do
10-
allow_creation_using_form true
19+
factory :model_with_has_many_field do
20+
after(:create) do |model, evaluator|
21+
create_list(:has_many_field, 1, model: model)
22+
end
1123
end
1224
end
1325
end

spec/models/kms/field_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
module Kms
4+
describe Field, type: :model do
5+
it { should belong_to(:model) }
6+
describe '#get_value' do
7+
it 'returns value stored in entry' do
8+
model = FactoryGirl.create(:model_with_string_field)
9+
field = model.fields.first
10+
entry = model.entries.create(values: {name: 'Test'})
11+
expect(field.get_value(entry)).to be_eql('Test')
12+
end
13+
end
14+
end
15+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
3+
module Kms
4+
describe HasManyField, type: :model do
5+
describe '#get_value' do
6+
it 'returns drop scope containing association records' do
7+
model = FactoryGirl.create(:model_with_has_many_field)
8+
field = model.fields.first
9+
associated_model = Kms::Model.find(field.class_name)
10+
association_entry = associated_model.entries.create(values: {name: 'Test'})
11+
entry = model.entries.create(values: { comments: [association_entry.id] })
12+
expect(field.get_value(entry)).to be_instance_of(Kms::EntryDrop::Scope)
13+
expect(field.get_value(entry).source).to include(association_entry)
14+
end
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)