custom_fields 0.0.0.1 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [Didier Lafforgue]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -6,7 +6,7 @@ Manage custom fields to a mongoid document or a collection. This module is one o
6
6
  Requirements
7
7
  =======
8
8
 
9
- MongoDB 1.6 and mongoid 2.0.0.beta16
9
+ ActiveSupport 3.0, MongoDB 1.6 and mongoid 2.0.0.beta17
10
10
 
11
11
 
12
12
  Example
@@ -1,11 +1,11 @@
1
1
  module CustomFields
2
-
2
+
3
3
  module CustomFieldsFor
4
-
4
+
5
5
  def self.included(base)
6
6
  base.extend(ClassMethods)
7
7
  end
8
-
8
+
9
9
  # Enhance an embedded collection by providing methods to manage custom fields
10
10
  #
11
11
  # class Company
@@ -18,33 +18,33 @@ module CustomFields
18
18
  # field :name, String
19
19
  # end
20
20
  #
21
- # company.employee_custom_fields.build :label => 'His/her position', :_alias => 'position', :kind => 'String'
21
+ # company.employee_custom_fields.build :label => 'His/her position', :_alias => 'position', :kind => 'string'
22
22
  #
23
23
  # company.employees.build :name => 'Michael Scott', :position => 'Regional manager'
24
24
  #
25
25
  module ClassMethods
26
-
26
+
27
27
  def custom_fields_for(collection_name)
28
28
  singular_name = collection_name.to_s.singularize
29
-
29
+
30
30
  class_eval <<-EOV
31
31
  field :#{singular_name}_custom_fields_counter, :type => Integer, :default => 0
32
-
32
+
33
33
  embeds_many :#{singular_name}_custom_fields, :class_name => "::CustomFields::Field"
34
-
34
+
35
35
  validates_associated :#{singular_name}_custom_fields
36
-
36
+
37
37
  accepts_nested_attributes_for :#{singular_name}_custom_fields, :allow_destroy => true
38
-
38
+
39
39
  def ordered_#{singular_name}_custom_fields
40
40
  self.#{singular_name}_custom_fields.sort { |a, b| (a.position || 0) <=> (b.position || 0) }
41
41
  end
42
-
42
+
43
43
  EOV
44
44
  end
45
-
45
+
46
46
  end
47
-
47
+
48
48
  end
49
-
49
+
50
50
  end
@@ -11,7 +11,7 @@ module CustomFields
11
11
 
12
12
  accepts_nested_attributes_for :category_items, :allow_destroy => true
13
13
 
14
- register_type :category, BSON::ObjectID
14
+ register_type :category, BSON::ObjectId
15
15
  end
16
16
 
17
17
  module InstanceMethods
@@ -0,0 +1,5 @@
1
+ module Mongoid
2
+ module CustomFields
3
+ VERSION = "1.0.0.beta"
4
+ end
5
+ end
data/lib/custom_fields.rb CHANGED
@@ -3,6 +3,7 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
3
3
  require 'active_support'
4
4
  require 'carrierwave/orm/mongoid'
5
5
 
6
+ require 'custom_fields/version'
6
7
  require 'custom_fields/extensions/mongoid/hierarchy'
7
8
  require 'custom_fields/extensions/mongoid/associations/proxy'
8
9
  require 'custom_fields/extensions/mongoid/associations/references_many'
@@ -19,10 +20,10 @@ require 'custom_fields/field'
19
20
  require 'custom_fields/custom_fields_for'
20
21
 
21
22
  module Mongoid
22
- module CustomFields
23
+ module CustomFields
23
24
  extend ActiveSupport::Concern
24
25
  included do
25
26
  include ::CustomFields::CustomFieldsFor
26
- end
27
+ end
27
28
  end
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_fields
3
3
  version: !ruby/object:Gem::Version
4
- hash: 77
5
- prerelease: false
4
+ hash: 31098193
5
+ prerelease: true
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 0
10
- - 1
11
- version: 0.0.0.1
10
+ - beta
11
+ version: 1.0.0.beta
12
12
  platform: ruby
13
13
  authors:
14
14
  - Didier Lafforgue
@@ -16,10 +16,57 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-22 00:00:00 +02:00
19
+ date: 2010-10-14 00:00:00 +02:00
20
20
  default_executable:
21
- dependencies: []
22
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: mongoid
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 62196423
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 0
35
+ - beta
36
+ - 18
37
+ version: 2.0.0.beta.18
38
+ type: :runtime
39
+ version_requirements: *id001
40
+ - !ruby/object:Gem::Dependency
41
+ name: activesupport
42
+ prerelease: false
43
+ requirement: &id002 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 7
49
+ segments:
50
+ - 3
51
+ - 0
52
+ - 0
53
+ version: 3.0.0
54
+ type: :runtime
55
+ version_requirements: *id002
56
+ - !ruby/object:Gem::Dependency
57
+ name: carrierwave
58
+ prerelease: false
59
+ requirement: &id003 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ type: :runtime
69
+ version_requirements: *id003
23
70
  description: Manage custom fields to a mongoid document or a collection. This module is one of the core features we implemented in our custom cms named Locomotive.
24
71
  email:
25
72
  - didier@nocoffee.fr
@@ -28,10 +75,12 @@ executables: []
28
75
  extensions: []
29
76
 
30
77
  extra_rdoc_files:
78
+ - MIT-LICENSE
31
79
  - README
32
80
  files:
33
81
  - init.rb
34
- - lib/custom_fields.rb
82
+ - MIT-LICENSE
83
+ - README
35
84
  - lib/custom_fields/custom_fields_for.rb
36
85
  - lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
37
86
  - lib/custom_fields/extensions/mongoid/associations/proxy.rb
@@ -46,30 +95,15 @@ files:
46
95
  - lib/custom_fields/types/file.rb
47
96
  - lib/custom_fields/types/string.rb
48
97
  - lib/custom_fields/types/text.rb
49
- - README
50
- - spec/integration/custom_fields_for_spec.rb
51
- - spec/integration/types/category_spec.rb
52
- - spec/integration/types/file_spec.rb
53
- - spec/models/person.rb
54
- - spec/models/project.rb
55
- - spec/models/task.rb
56
- - spec/spec_helper.rb
57
- - spec/support/carrierwave.rb
58
- - spec/support/mongoid.rb
59
- - spec/unit/custom_field_spec.rb
60
- - spec/unit/custom_fields_for_spec.rb
61
- - spec/unit/proxy_class_enabler_spec.rb
62
- - spec/unit/types/boolean_spec.rb
63
- - spec/unit/types/category_spec.rb
64
- - spec/unit/types/date_spec.rb
65
- - spec/unit/types/file_spec.rb
98
+ - lib/custom_fields/version.rb
99
+ - lib/custom_fields.rb
66
100
  has_rdoc: true
67
101
  homepage: http://github.com/locomotivecms/custom_fields
68
102
  licenses: []
69
103
 
70
104
  post_install_message:
71
- rdoc_options:
72
- - --charset=UTF-8
105
+ rdoc_options: []
106
+
73
107
  require_paths:
74
108
  - lib
75
109
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -86,31 +120,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
120
  requirements:
87
121
  - - ">="
88
122
  - !ruby/object:Gem::Version
89
- hash: 3
123
+ hash: 23
90
124
  segments:
91
- - 0
92
- version: "0"
125
+ - 1
126
+ - 3
127
+ - 6
128
+ version: 1.3.6
93
129
  requirements: []
94
130
 
95
- rubyforge_project:
131
+ rubyforge_project: nowarning
96
132
  rubygems_version: 1.3.7
97
133
  signing_key:
98
134
  specification_version: 3
99
- summary: Custom fields plugin for Mongoid
100
- test_files:
101
- - spec/integration/custom_fields_for_spec.rb
102
- - spec/integration/types/category_spec.rb
103
- - spec/integration/types/file_spec.rb
104
- - spec/models/person.rb
105
- - spec/models/project.rb
106
- - spec/models/task.rb
107
- - spec/spec_helper.rb
108
- - spec/support/carrierwave.rb
109
- - spec/support/mongoid.rb
110
- - spec/unit/custom_field_spec.rb
111
- - spec/unit/custom_fields_for_spec.rb
112
- - spec/unit/proxy_class_enabler_spec.rb
113
- - spec/unit/types/boolean_spec.rb
114
- - spec/unit/types/category_spec.rb
115
- - spec/unit/types/date_spec.rb
116
- - spec/unit/types/file_spec.rb
135
+ summary: Custom fields extension for Mongoid
136
+ test_files: []
137
+
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::CustomFieldsFor do
4
-
5
- describe 'Saving' do
6
-
7
- before(:each) do
8
- @project = Project.new(:name => 'Locomotive')
9
- @project.person_custom_fields.build(:label => 'E-mail', :_alias => 'email', :kind => 'String')
10
- @project.person_custom_fields.build(:label => 'Age', :_alias => 'age', :kind => 'String')
11
- end
12
-
13
- context '@create' do
14
-
15
- it 'persists parent object' do
16
- lambda { @project.save }.should change(Project, :count).by(1)
17
- end
18
-
19
- it 'persists custom fields' do
20
- @project.save && @project.reload
21
- @project.person_custom_fields.count.should == 2
22
- end
23
-
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Types::Category do
4
-
5
- before(:each) do
6
- @project = Project.new(:name => 'Locomotive')
7
- @field = @project.task_custom_fields.build(:label => 'Main category', :_alias => 'main_category', :kind => 'Category')
8
- end
9
-
10
- context 'saving category items' do
11
-
12
- before(:each) do
13
- @field.category_items.build :name => 'Development'
14
- @field.category_items.build :name => 'Design'
15
- @field.updated_at = Time.now
16
- end
17
-
18
- it 'persists items' do
19
- @field.save.should be_true
20
- @project.reload
21
- @project.task_custom_fields.first.category_items.size.should == 2
22
- end
23
-
24
- context 'assigning a category and persists' do
25
-
26
- it 'sets the category from a category name' do
27
- task = @project.tasks.build(:main_category => 'Design')
28
- task.save && @project.reload
29
- @project.tasks.first.main_category.should == 'Design'
30
- end
31
-
32
- it 'sets the category from an id (string)' do
33
- task = @project.tasks.build(:main_category => @field.category_items.last._id.to_s)
34
- task.save && @project.reload
35
- @project.tasks.first.main_category.should == 'Design'
36
- end
37
-
38
- it 'sets the category from an id (BSON::ObjectID)' do
39
- task = @project.tasks.build(:main_category => @field.category_items.last._id)
40
- task.save && @project.reload
41
- @project.tasks.first.main_category.should == 'Design'
42
- end
43
-
44
- end
45
-
46
- end
47
-
48
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Types::File do
4
-
5
- before(:each) do
6
- @project = Project.new(:name => 'Locomotive')
7
- @project.task_custom_fields.build(:label => 'Screenshot', :_alias => 'screenshot', :kind => 'File')
8
- @project.save
9
- @task = @project.tasks.build
10
- end
11
-
12
- it 'attaches file' do
13
- @task.screenshot = FixturedFile.open('doc.txt')
14
- @task.save
15
- @task.screenshot.url.should == '/uploads/doc.txt'
16
- end
17
-
18
- end
@@ -1,10 +0,0 @@
1
- class Person
2
-
3
- include Mongoid::Document
4
- include CustomFields::ProxyClassEnabler
5
-
6
- field :full_name
7
-
8
- embedded_in :project, :inverse_of => :people
9
-
10
- end
@@ -1,18 +0,0 @@
1
- class Project
2
-
3
- include Mongoid::Document
4
- include CustomFields::ProxyClassEnabler
5
- include CustomFields::CustomFieldsFor
6
-
7
- field :name
8
- field :description
9
-
10
- references_many :people
11
- embeds_many :tasks
12
-
13
- custom_fields_for :people
14
- custom_fields_for :tasks
15
-
16
- scope :ordered, :order_by => [[:name, :asc]]
17
-
18
- end
data/spec/models/task.rb DELETED
@@ -1,10 +0,0 @@
1
- class Task
2
-
3
- include Mongoid::Document
4
- include CustomFields::ProxyClassEnabler
5
-
6
- field :title
7
-
8
- embedded_in :project, :inverse_of => :tasks
9
-
10
- end
data/spec/spec_helper.rb DELETED
@@ -1,27 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- MODELS = File.join(File.dirname(__FILE__), 'models')
5
- $LOAD_PATH.unshift(MODELS)
6
-
7
- require 'rubygems'
8
- require 'bundler'
9
- Bundler.setup
10
- Bundler.require
11
-
12
- require 'mongoid'
13
- require 'mocha'
14
- require 'rspec'
15
- require 'custom_fields'
16
-
17
- Dir[ File.join(MODELS, "*.rb") ].sort.each { |file| require File.basename(file) }
18
-
19
- require 'support/mongoid'
20
- require 'support/carrierwave'
21
-
22
- Rspec.configure do |config|
23
- config.mock_with :mocha
24
- config.after :suite do
25
- Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
26
- end
27
- end
@@ -1,31 +0,0 @@
1
- require 'carrierwave/test/matchers'
2
-
3
- CarrierWave.configure do |config|
4
- config.storage = :file
5
- config.store_dir = "uploads"
6
- config.cache_dir = "cache"
7
- config.root = File.join(File.dirname(__FILE__), '..', 'tmp')
8
- end
9
-
10
- module FixturedFile
11
- def self.open(filename)
12
- File.new(self.path(filename))
13
- end
14
-
15
- def self.path(filename)
16
- File.join(File.dirname(__FILE__), '..', 'fixtures', filename)
17
- end
18
-
19
- def self.duplicate(filename)
20
- dst = File.join(File.dirname(__FILE__), '..', 'tmp', filename)
21
- FileUtils.cp self.path(filename), dst
22
- dst
23
- end
24
-
25
- def self.reset!
26
- FileUtils.rm_rf(File.join(File.dirname(__FILE__), '..', 'tmp'))
27
- FileUtils.mkdir(File.join(File.dirname(__FILE__), '..', 'tmp'))
28
- end
29
- end
30
-
31
- FixturedFile.reset!
@@ -1,6 +0,0 @@
1
- Mongoid.configure do |config|
2
- name = "custom_fields_test"
3
- host = "localhost"
4
- config.master = Mongo::Connection.new.db(name)
5
- # config.master = Mongo::Connection.new('localhost', '27017', :logger => Logger.new($stdout)).db(name)
6
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Field do
4
-
5
- it 'is initialized' do
6
- lambda { CustomFields::Field.new }.should_not raise_error
7
- end
8
-
9
- context '#mongoid' do
10
-
11
- before(:each) do
12
- @field = CustomFields::Field.new(:label => 'manager', :_name => 'field_1', :kind => 'String', :_alias => 'manager')
13
- @field.stubs(:valid?).returns(true)
14
- @project = Project.to_klass_with_custom_fields(@field).new
15
- end
16
-
17
- it 'is added to the list of mongoid fields' do
18
- @project.fields['field_1'].should_not be_nil
19
- end
20
-
21
- end
22
-
23
- context 'on target class' do
24
-
25
- before(:each) do
26
- @field = CustomFields::Field.new(:label => 'manager', :_name => 'field_1', :kind => 'String', :_alias => 'manager')
27
- @field.stubs(:valid?).returns(true)
28
- @project = Project.to_klass_with_custom_fields(@field).new
29
- end
30
-
31
- it 'has a new field' do
32
- @project.respond_to?(:manager).should be_true
33
- end
34
-
35
- it 'sets / retrieves a value' do
36
- @project.manager = 'Mickael Scott'
37
- @project.manager.should == 'Mickael Scott'
38
- end
39
-
40
- end
41
-
42
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::CustomFieldsFor do
4
-
5
- context '#proxy class' do
6
-
7
- before(:each) do
8
- @project = Project.new
9
- @klass = @project.tasks.klass
10
- end
11
-
12
- it 'returns the proxy class in the association' do
13
- @klass.should == @project.tasks.build.class
14
- end
15
-
16
- it 'has a link to the parent' do
17
- @klass._parent.should == @project
18
- end
19
-
20
- it 'has the association name which references to' do
21
- @klass.association_name.should == 'tasks'
22
- end
23
-
24
- end
25
-
26
- context 'with embedded collection' do
27
-
28
- context '#association' do
29
-
30
- before(:each) do
31
- @project = Project.new
32
- end
33
-
34
- it 'has custom fields for embedded collection' do
35
- @project.respond_to?(:task_custom_fields).should be_true
36
- end
37
-
38
- end
39
-
40
- context '#building' do
41
-
42
- before(:each) do
43
- @project = Project.new
44
- @project.task_custom_fields.build :label => 'Short summary', :_alias => 'summary', :kind => 'String'
45
- @task = @project.tasks.build
46
- end
47
-
48
- it 'returns a new document whose Class is different from the original one' do
49
- @task.class.should_not == Task
50
- end
51
-
52
- it 'returns a new document with custom field' do
53
- @project.tasks.build
54
- @project.tasks.build
55
- @task.respond_to?(:summary).should be_true
56
- end
57
-
58
- it 'sets/gets custom attributes' do
59
- @task.summary = 'Lorem ipsum...'
60
- @task.summary.should == 'Lorem ipsum...'
61
- end
62
-
63
- end
64
-
65
- end
66
-
67
- context 'with related collection' do
68
-
69
- context '#association' do
70
-
71
- before(:each) do
72
- @project = Project.new
73
- end
74
-
75
- it 'has custom fields for related collections' do
76
- @project.respond_to?(:person_custom_fields).should be_true
77
- end
78
-
79
- end
80
-
81
- context '#building' do
82
-
83
- before(:each) do
84
- @project = Project.new
85
- @project.person_custom_fields.build :label => 'Position in the project', :_alias => 'position', :kind => 'String'
86
- @person = @project.people.build
87
- end
88
-
89
- it 'returns a new document whose Class is different from the original one' do
90
- @person.class.should_not == Person
91
- end
92
-
93
- it 'returns a new document with custom field' do
94
- @person.respond_to?(:position).should be_true
95
- end
96
-
97
- it 'sets/gets custom attributes' do
98
- @person.position = 'Designer'
99
- @person.position.should == 'Designer'
100
- end
101
-
102
- end
103
-
104
- end
105
-
106
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::ProxyClassEnabler do
4
-
5
- context '#proxy klass' do
6
-
7
- before(:each) do
8
- @klass = Task.to_klass_with_custom_fields([])
9
- end
10
-
11
- it 'does not be flagged as a inherited document' do
12
- @klass.new.hereditary?.should be_false
13
- end
14
-
15
- it 'has a list of custom fields' do
16
- @klass.custom_fields.should == []
17
- end
18
-
19
- it 'has the exact same model name than its parent' do
20
- @klass.model_name.should == 'Task'
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Types::Boolean do
4
-
5
- context 'on field class' do
6
-
7
- before(:each) do
8
- @field = CustomFields::Field.new
9
- end
10
-
11
- it 'returns true if it is a Boolean' do
12
- @field.kind = 'boolean'
13
- @field.boolean?.should be_true
14
- end
15
-
16
- it 'returns false if it is not a Boolean' do
17
- @field.kind = 'string'
18
- @field.boolean?.should be_false
19
- end
20
-
21
- end
22
-
23
- context 'on target class' do
24
-
25
- before(:each) do
26
- @project = build_project_with_boolean
27
- end
28
-
29
- context '#setting' do
30
-
31
- context '#true' do
32
-
33
- it 'sets value from an integer' do
34
- @project.active = 1
35
- @project.active.should == true
36
- @project.field_1.should == '1'
37
- end
38
-
39
- it 'sets value from a string' do
40
- @project.active = '1'
41
- @project.active.should == true
42
- @project.field_1.should == '1'
43
-
44
- @project.active = 'true'
45
- @project.active.should == true
46
- @project.field_1.should == 'true'
47
- end
48
-
49
- end
50
-
51
- context '#false' do
52
-
53
- it 'sets value from an integer' do
54
- @project.active = 0
55
- @project.active.should == false
56
- @project.field_1.should == '0'
57
- end
58
-
59
- it 'sets value from a string' do
60
- @project.active = '0'
61
- @project.active.should == false
62
- @project.field_1.should == '0'
63
-
64
- @project.active = 'false'
65
- @project.active.should == false
66
- @project.field_1.should == 'false'
67
- end
68
-
69
- end
70
-
71
- end
72
-
73
- end
74
-
75
- def build_project_with_boolean
76
- field = CustomFields::Field.new(:label => 'Active', :_name => 'field_1', :kind => 'Boolean')
77
- field.stubs(:valid?).returns(true)
78
- Project.to_klass_with_custom_fields(field).new
79
- end
80
-
81
- end
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Types::Category do
4
-
5
- context 'on field class' do
6
-
7
- before(:each) do
8
- @field = CustomFields::Field.new
9
- end
10
-
11
- it 'has the category items field' do
12
- @field.respond_to?(:category_items).should be_true
13
- end
14
-
15
- it 'has the apply method used for the target object' do
16
- @field.respond_to?(:apply_category_type).should be_true
17
- end
18
-
19
- it 'returns true if it is a Category' do
20
- @field.kind = 'category'
21
- @field.category?.should be_true
22
- end
23
-
24
- it 'returns false if it is not a Category' do
25
- @field.kind = 'string'
26
- @field.category?.should be_false
27
- end
28
-
29
- end
30
-
31
- context 'on target class' do
32
-
33
- before(:each) do
34
- @project = build_project_with_category
35
- end
36
-
37
- it 'has getter/setter' do
38
- @project.respond_to?(:global_category).should be_true
39
- @project.respond_to?(:global_category=).should be_true
40
- end
41
-
42
- it 'has the values of this category' do
43
- @project.class.global_category_names.should == %w{Maintenance Design Development}
44
- end
45
-
46
- it 'sets the category from a name' do
47
- @project.global_category = 'Design'
48
- @project.global_category.should == 'Design'
49
- @project.field_1.should == fake_bson_id(42)
50
- end
51
-
52
- it 'does not set the category if it does not exit' do
53
- @project.global_category = 'Accounting'
54
- @project.global_category.should be_nil
55
- @project.field_1.should be_nil
56
- end
57
-
58
- context 'group by category' do
59
-
60
- before(:each) do
61
- seed_projects
62
- @groups = @project.class.group_by_global_category
63
- end
64
-
65
- it 'is an non empty array' do
66
- @groups.class.should == Array
67
- @groups.size.should == 3
68
- end
69
-
70
- it 'is an array of hash composed of a name' do
71
- @groups.collect { |g| g[:name] }.should == %w{Maintenance Design Development}
72
- end
73
-
74
- it 'is an array of hash composed of a list of objects' do
75
- @groups[0][:items].size.should == 0
76
- @groups[1][:items].size.should == 1
77
- @groups[2][:items].size.should == 2
78
- end
79
-
80
- it 'passes method to retrieve items' do
81
- @project.class.expects(:ordered)
82
- @project.class.group_by_global_category(:ordered)
83
- end
84
-
85
- end
86
-
87
- end
88
-
89
- def build_project_with_category
90
- field = build_category
91
- Project.to_klass_with_custom_fields(field).new
92
- end
93
-
94
- def build_category
95
- field = CustomFields::Field.new(:label => 'global_category', :_name => 'field_1', :kind => 'Category')
96
- field.stubs(:valid?).returns(true)
97
- field.category_items.build :name => 'Development', :_id => fake_bson_id(41), :position => 2
98
- field.category_items.build :name => 'Design', :_id => fake_bson_id(42), :position => 1
99
- field.category_items.build :name => 'Maintenance', :_id => fake_bson_id(43), :position => 0
100
- field
101
- end
102
-
103
- def seed_projects
104
- list = [
105
- @project.class.new(:name => 'Locomotive CMS', :global_category => fake_bson_id(41)),
106
- @project.class.new(:name => 'Ruby on Rails', :global_category => fake_bson_id(41)),
107
- @project.class.new(:name => 'Dribble', :global_category => fake_bson_id(42))
108
- ]
109
- @project.class.stubs(:all).returns(list)
110
- end
111
-
112
- def fake_bson_id(id)
113
- BSON::ObjectID(id.to_s.rjust(24, '0'))
114
- end
115
-
116
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Types::Date do
4
-
5
- context 'on field class' do
6
-
7
- before(:each) do
8
- @field = CustomFields::Field.new
9
- end
10
-
11
- it 'returns true if it is a Date' do
12
- @field.kind = 'Date'
13
- @field.date?.should be_true
14
- end
15
-
16
- it 'returns false if it is not a Date' do
17
- @field.kind = 'string'
18
- @field.date?.should be_false
19
- end
20
-
21
- end
22
-
23
- context 'on target class' do
24
-
25
- before(:each) do
26
- @project = build_project_with_date
27
- @date = Date.parse('2010-06-29')
28
- end
29
-
30
- it 'sets value from a date' do
31
- @project.started_at = @date
32
- @project.started_at.should == '2010-06-29'
33
- @project.field_1.class.should == Date
34
- @project.field_1.should == @date
35
- end
36
-
37
- it 'sets value from a string' do
38
- @project.started_at = '2010-06-29'
39
- @project.started_at.class.should == String
40
- @project.started_at.should == '2010-06-29'
41
- @project.field_1.class.should == Date
42
- @project.field_1.should == @date
43
- end
44
-
45
- it 'sets nil value' do
46
- @project.started_at = nil
47
- @project.started_at.should be_nil
48
- @project.field_1.should be_nil
49
- end
50
-
51
- end
52
-
53
- def build_project_with_date
54
- field = CustomFields::Field.new(:label => 'Started at', :_name => 'field_1', :kind => 'Date')
55
- field.stubs(:valid?).returns(true)
56
- Project.to_klass_with_custom_fields(field).new
57
- end
58
-
59
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CustomFields::Types::Date do
4
-
5
- context 'on field class' do
6
-
7
- before(:each) do
8
- @field = CustomFields::Field.new
9
- end
10
-
11
- it 'returns true if it is a Date' do
12
- @field.kind = 'File'
13
- @field.file?.should be_true
14
- end
15
-
16
- it 'returns false if it is not a Date' do
17
- @field.kind = 'string'
18
- @field.file?.should be_false
19
- end
20
-
21
- end
22
-
23
- end