engine-rea 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/app/models/rea/category.rb +4 -0
- data/app/models/rea/category_member.rb +1 -0
- data/app/models/rea/category_type.rb +1 -1
- data/app/models/rea/group.rb +17 -6
- data/app/models/rea/group_type.rb +7 -0
- data/app/models/rea/identifier.rb +12 -3
- data/config/locales/en.yml +4 -0
- data/config/locales/zh-CN.yml +42 -0
- data/db/migrate/20120601074531_create_rea_category_types.rb +1 -1
- data/db/migrate/20120601074540_create_rea_categories.rb +1 -1
- data/db/migrate/20120605030658_create_rea_groups.rb +14 -3
- data/db/migrate/20120605082028_create_rea_identifiers.rb +2 -2
- data/db/migrate/20120717080004_create_rea_group_types.rb +7 -0
- data/engine-rea.gemspec +31 -14
- data/lib/generators/rea/install/install_generator.rb +8 -0
- data/lib/rails_patch.rb +26 -0
- data/lib/rea.rb +25 -1
- data/lib/rea/application.rb +86 -0
- data/lib/rea/aspect_type.rb +28 -6
- data/lib/rea/aspect_type/base.rb +3 -2
- data/lib/rea/aspect_type/classification.rb +142 -0
- data/lib/rea/aspect_type/description.rb +3 -2
- data/lib/rea/aspect_type/due_date.rb +34 -0
- data/lib/rea/aspect_type/identification.rb +38 -0
- data/lib/rea/engine.rb +1 -3
- data/lib/rea/meta_type.rb +1 -1
- data/lib/rea/meta_type/agent.rb +1 -1
- data/lib/rea/meta_type/commitment.rb +5 -6
- data/lib/rea/meta_type/contract.rb +17 -4
- data/lib/rea/meta_type/conversion.rb +6 -0
- data/lib/rea/meta_type/entity.rb +61 -20
- data/lib/rea/meta_type/event.rb +17 -24
- data/lib/rea/meta_type/exchange.rb +6 -0
- data/lib/rea/meta_type/group.rb +25 -0
- data/lib/rea/meta_type/process.rb +28 -0
- data/lib/rea/meta_type/resource.rb +5 -1
- data/lib/rea/model.rb +65 -0
- data/lib/rea/settings.rb +58 -0
- data/spec/dummy/db/schema.rb +1 -56
- data/spec/generators/rea/install/install_generator_spec.rb +2 -0
- data/spec/models/rea/category_member_spec.rb +5 -1
- data/spec/models/rea/category_spec.rb +19 -1
- data/spec/models/rea/category_type_spec.rb +24 -1
- data/spec/models/rea/group_spec.rb +34 -1
- data/spec/models/rea/group_type_spec.rb +8 -0
- data/spec/rea/application_spec.rb +8 -0
- data/spec/rea/aspect_type/classification_spec.rb +107 -0
- data/spec/rea/aspect_type/due_date_spec.rb +75 -0
- data/spec/rea/aspect_type/identification_spec.rb +64 -0
- data/spec/rea/aspect_type_spec.rb +44 -0
- data/spec/rea/engine_spec.rb +0 -3
- data/spec/rea/meta_type/agent_spec.rb +28 -0
- data/spec/rea/meta_type/commitment_spec.rb +45 -0
- data/spec/rea/meta_type/contract_spec.rb +42 -0
- data/spec/rea/meta_type/entity_spec.rb +58 -0
- data/spec/rea/meta_type/event_spec.rb +21 -0
- data/spec/rea/meta_type/group_spec.rb +55 -0
- data/spec/rea/meta_type/process_spec.rb +5 -0
- data/spec/rea/meta_type/resource_spec.rb +65 -0
- data/spec/rea/meta_type_spec.rb +1 -1
- data/spec/rea/model_spec.rb +79 -0
- metadata +32 -15
- data/app/models/rea/group_entity.rb +0 -7
- data/db/migrate/20120605030708_create_rea_group_entities.rb +0 -9
- data/lib/rea/aspect_type/classification_aspect.rb +0 -75
- data/lib/rea/aspect_type/due_date_type.rb +0 -5
- data/lib/rea/aspect_type/identifier_setup.rb +0 -7
- data/lib/rea/dsl.rb +0 -24
- data/lib/rea/dsl/behavioral.rb +0 -50
- data/lib/rea/dsl/structural.rb +0 -53
- data/spec/models/rea/group_entity_spec.rb +0 -5
- data/spec/rea/dsl/behavioral_spec.rb +0 -149
- data/spec/rea/dsl/structural_spec.rb +0 -299
- data/spec/rea/dsl_spec.rb +0 -11
data/lib/rea/dsl.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Rea
|
2
|
-
module Dsl
|
3
|
-
|
4
|
-
autoload :Structural, 'rea/dsl/structural'
|
5
|
-
autoload :Behavioral, 'rea/dsl/behavioral'
|
6
|
-
|
7
|
-
|
8
|
-
def self.included base
|
9
|
-
base.extend ClassMethods
|
10
|
-
base.cattr_reader :rea, :rea_ast
|
11
|
-
base.cattr_accessor :type, :fields
|
12
|
-
base.class_variable_set "@@rea", {}
|
13
|
-
base.class_variable_set "@@rea_ast", {}
|
14
|
-
base.class_eval do
|
15
|
-
include Structural
|
16
|
-
include Behavioral
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
data/lib/rea/dsl/behavioral.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Rea
|
2
|
-
module Dsl
|
3
|
-
module Behavioral
|
4
|
-
def self.included base
|
5
|
-
base.extend ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
def create_id_string
|
9
|
-
id_setup = self.class.rea_ast[:identifier]
|
10
|
-
self.send("#{id_setup.name}=", Rea::Identifier.find_last_by_name(id_setup.identifier).try(:generate))
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
|
15
|
-
def classification options={}, &block
|
16
|
-
include ::Rea::AspectType::Classification
|
17
|
-
rea_ast[:classification] = {}
|
18
|
-
Rea::CategoryType.find_or_create_by_name name.to_s, options
|
19
|
-
block.call if block_given?
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def identification name, identifier
|
24
|
-
rea_ast[:identifier] = ::Rea::AspectType::IdentifierSetup.new :name=>name, :identifier=>identifier
|
25
|
-
self.before_create :create_id_string
|
26
|
-
end
|
27
|
-
|
28
|
-
def description name, media, options={}
|
29
|
-
rea[name] = ::Rea::AspectType::Description.new :name=>name, :media=>media
|
30
|
-
end
|
31
|
-
|
32
|
-
def due_date name, options={}
|
33
|
-
options = {:name=>name, :activation_rule=>'true'}.merge(options)
|
34
|
-
rea[name] = ::Rea::AspectType::DueDateType.new options
|
35
|
-
define_method "#{name}_state".to_sym do
|
36
|
-
if try(name).nil?
|
37
|
-
:disabled
|
38
|
-
else
|
39
|
-
if send(name) > Time.now
|
40
|
-
:incoming
|
41
|
-
else
|
42
|
-
:expired
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/rea/dsl/structural.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Rea
|
2
|
-
module Dsl
|
3
|
-
module Structural
|
4
|
-
def self.included base
|
5
|
-
base.extend ClassMethods
|
6
|
-
if base == ActiveRecord::Base
|
7
|
-
|
8
|
-
else
|
9
|
-
base.class_eval do
|
10
|
-
include ::Rea::Plugins::ActiveModel
|
11
|
-
def initialize options = {}
|
12
|
-
options.keys.each do |key|
|
13
|
-
instance_variable_set "@#{key}", options[key]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
module ClassMethods
|
22
|
-
|
23
|
-
def acts_as_resource options={}, &block
|
24
|
-
include ::Rea::MetaType::Resource
|
25
|
-
block.call if block_given?
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def acts_as_commitment options={}, &block
|
30
|
-
include ::Rea::MetaType::Commitment
|
31
|
-
yield
|
32
|
-
end
|
33
|
-
|
34
|
-
def acts_as_event options={}, &block
|
35
|
-
include ::Rea::MetaType::Event
|
36
|
-
block.call if block_given?
|
37
|
-
end
|
38
|
-
|
39
|
-
def acts_as_agent options={}, &block
|
40
|
-
include ::Rea::MetaType::Agent
|
41
|
-
yield if block_given?
|
42
|
-
end
|
43
|
-
|
44
|
-
def acts_as_contract options={}
|
45
|
-
include ::Rea::MetaType::Contract
|
46
|
-
yield if block_given?
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rea::Dsl::Behavioral do
|
4
|
-
|
5
|
-
context :identification do
|
6
|
-
with_model :entity do
|
7
|
-
table do |t|
|
8
|
-
t.string :name
|
9
|
-
t.string :value
|
10
|
-
t.string :sn
|
11
|
-
end
|
12
|
-
model do
|
13
|
-
acts_as_resource do
|
14
|
-
identification :sn, :entity_sn
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context :sematics do
|
20
|
-
subject { Entity.rea_ast }
|
21
|
-
its([:identifier]) { should be_a_kind_of Rea::AspectType::IdentifierSetup }
|
22
|
-
end
|
23
|
-
|
24
|
-
context :model do
|
25
|
-
subject { Entity.create :name=>:entity, :value=>1 }
|
26
|
-
|
27
|
-
before(:all) { Rea::Identifier.create! :name=>:entity_sn, :id_rule=>'#{"%010d" % last_value}' }
|
28
|
-
|
29
|
-
it { should be_valid }
|
30
|
-
its(:sn) { should_not be_nil }
|
31
|
-
its(:sn) { should =~ /\d{10}/ }
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
context :classification do
|
37
|
-
|
38
|
-
with_model :entity do
|
39
|
-
table do |t|
|
40
|
-
t.string :name
|
41
|
-
t.string :value
|
42
|
-
t.string :category
|
43
|
-
end
|
44
|
-
model do
|
45
|
-
acts_as_resource do
|
46
|
-
classification do
|
47
|
-
category_type 'category_type_one' do |ct|
|
48
|
-
ct.category :cate_1 do |c|
|
49
|
-
c.category :cate_2, :cate_3
|
50
|
-
end
|
51
|
-
end
|
52
|
-
category_type 'category_type_two', :automatic=>true, :system=>true do |ct|
|
53
|
-
ct.category :category_one, :category_two
|
54
|
-
ct.category :category_tree do |c|
|
55
|
-
c.category :category_node_1, :category_node_2, :category_node_3
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
member :category, :type=>:category_type_one
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context :sematics do
|
65
|
-
|
66
|
-
context :category_type_defaults do
|
67
|
-
subject { Rea::CategoryType.find_by_name 'category_type_one' }
|
68
|
-
|
69
|
-
it { should_not be_nil }
|
70
|
-
it { should_not be_system }
|
71
|
-
it { should_not be_multiple }
|
72
|
-
it { should_not be_automatic }
|
73
|
-
end
|
74
|
-
|
75
|
-
context :category_type_two do
|
76
|
-
subject { Rea::CategoryType.find_by_name 'category_type_two' }
|
77
|
-
|
78
|
-
it { should_not be_nil }
|
79
|
-
its(:categories) { should have(6).items }
|
80
|
-
context :category_tree do
|
81
|
-
subject { Rea::Category.find_by_name('category_tree').child_categories }
|
82
|
-
it { should have(3).items }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context :rea do
|
87
|
-
subject { Entity.rea }
|
88
|
-
its([:category]) { should be_a_kind_of(Rea::AspectType::MemberType) }
|
89
|
-
end
|
90
|
-
context :member_field do
|
91
|
-
subject { Entity.rea[:category] }
|
92
|
-
its(:category_options) { should have(3).items }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
context :model do
|
96
|
-
context :entity do
|
97
|
-
context :methods do
|
98
|
-
let(:cate_3) { Rea::Category.find_by_name :cate_3 }
|
99
|
-
let(:cate_1) { Rea::Category.find_by_name :cate_1 }
|
100
|
-
subject { Entity.create :name=>:name, :value=>1, :category=>:cate_3 }
|
101
|
-
it { subject.is(cate_3).should be_true }
|
102
|
-
it { subject.is_in(cate_1).should be_true }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context :description do
|
109
|
-
|
110
|
-
with_model :entity do
|
111
|
-
table do |t|
|
112
|
-
end
|
113
|
-
model do
|
114
|
-
acts_as_resource do
|
115
|
-
description :text, :text
|
116
|
-
description :markdown, :md
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
subject { Entity.rea }
|
122
|
-
its([:text]) { should be_a_kind_of(Rea::AspectType::Description) }
|
123
|
-
end
|
124
|
-
|
125
|
-
context :due_date do
|
126
|
-
with_model :entity do
|
127
|
-
table do |t|
|
128
|
-
t.datetime :date_one
|
129
|
-
t.datetime :date_two
|
130
|
-
end
|
131
|
-
model do
|
132
|
-
acts_as_resource do
|
133
|
-
due_date :date_one
|
134
|
-
due_date :date_two, :activation_rule=>'date_one.nil?'
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context :sematics do
|
140
|
-
subject { Entity.rea }
|
141
|
-
its([:date_one]) { should be_a_kind_of(::Rea::AspectType::DueDateType) }
|
142
|
-
end
|
143
|
-
context :model do
|
144
|
-
subject { Entity.new :date_one=>1.day.ago, :date_two=>nil }
|
145
|
-
its(:date_one_state) { should == :expired }
|
146
|
-
its(:date_two_state) { should == :disabled }
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
@@ -1,299 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rea::Dsl::Structural do
|
4
|
-
shared_examples "entities" do |attrs, defaults|
|
5
|
-
context :definations do
|
6
|
-
let!(:entity) { entity_class.new defaults }
|
7
|
-
subject { entity_class }
|
8
|
-
attrs.each do |attr|
|
9
|
-
its(:public_instance_methods) { should include attr }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
context :validations do
|
13
|
-
context :valid do
|
14
|
-
subject { (entity_class).new defaults }
|
15
|
-
after(:each) { pp subject.errors unless subject.valid? }
|
16
|
-
it { should be_valid }
|
17
|
-
end
|
18
|
-
context :invalid do
|
19
|
-
subject { (entity_class).new }
|
20
|
-
it { should_not be_valid }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.create_entity_model name, columns = [:name, :value], &block
|
26
|
-
with_model name do
|
27
|
-
table do |t|
|
28
|
-
columns.each do |c| t.string c end
|
29
|
-
end
|
30
|
-
model &block
|
31
|
-
end
|
32
|
-
let!(:entity_class) { name.to_s.camelize.constantize }
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
context :acts_as_resource do
|
37
|
-
context :active_record do
|
38
|
-
with_model :resource do
|
39
|
-
table do |t|
|
40
|
-
t.string :name
|
41
|
-
t.decimal :value
|
42
|
-
end
|
43
|
-
model do
|
44
|
-
acts_as_resource
|
45
|
-
end
|
46
|
-
end
|
47
|
-
let!(:entity_class) { Resource }
|
48
|
-
include_examples "entities", [:name, :value], :name=>:name, :value=>1
|
49
|
-
end
|
50
|
-
|
51
|
-
context :simple_class do
|
52
|
-
class SimpleResource
|
53
|
-
include Rea::Dsl
|
54
|
-
acts_as_resource do
|
55
|
-
item :rmb, :id=>1, :value=>1
|
56
|
-
item :usd, :id=>2, :value=>6.78
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
entity_class = SimpleResource
|
61
|
-
let!(:entity_class) { entity_class }
|
62
|
-
include_examples "entities", [:name, :value], :name=>:name, :value=>1
|
63
|
-
context :nested_items do
|
64
|
-
subject { entity_class }
|
65
|
-
its("rmb.value") { should == 1 }
|
66
|
-
its("rmb.name") { should == "rmb" }
|
67
|
-
its("usd.value") { should == 6.78 }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context :acts_as_agent do
|
73
|
-
context :active_record do
|
74
|
-
create_entity_model(:agent, [:name]) do acts_as_agent end
|
75
|
-
include_examples "entities", [:name], :name=>:name
|
76
|
-
end
|
77
|
-
|
78
|
-
context :simple_class do
|
79
|
-
class SimpleAgent
|
80
|
-
include Rea::Dsl
|
81
|
-
acts_as_agent do
|
82
|
-
item :facebook, :id=>1
|
83
|
-
item :google, :id=>2
|
84
|
-
end
|
85
|
-
end
|
86
|
-
entity_class = SimpleAgent
|
87
|
-
let!(:entity_class) { entity_class}
|
88
|
-
include_examples "entities", [:name], :name=>:name
|
89
|
-
context :nested_items do
|
90
|
-
subject { entity_class }
|
91
|
-
its("facebook.name") { should == "facebook" }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
context :acts_as_event do
|
98
|
-
context :active_record do
|
99
|
-
with_model :resource do
|
100
|
-
table do |t|
|
101
|
-
t.string :name
|
102
|
-
t.decimal :value
|
103
|
-
end
|
104
|
-
model do
|
105
|
-
acts_as_resource
|
106
|
-
end
|
107
|
-
end
|
108
|
-
with_model :agent do
|
109
|
-
table do |t|
|
110
|
-
t.string :name
|
111
|
-
end
|
112
|
-
model do
|
113
|
-
acts_as_agent
|
114
|
-
end
|
115
|
-
end
|
116
|
-
with_model :increment_event do
|
117
|
-
table do |t|
|
118
|
-
t.references :resource
|
119
|
-
t.references :provider
|
120
|
-
t.decimal :amount
|
121
|
-
t.timestamps
|
122
|
-
end
|
123
|
-
model do
|
124
|
-
acts_as_event do
|
125
|
-
resource Resource
|
126
|
-
provider Agent
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
let!(:entity_class) { IncrementEvent }
|
131
|
-
include_examples "entities", [:resource, :amount, :provider ], {:resource_id=>1,:provider_id=>1,:amount=>1}
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
context :acts_as_increment_commitment do
|
136
|
-
context :active_record do
|
137
|
-
with_model :resource do
|
138
|
-
table do |t|
|
139
|
-
t.string :name
|
140
|
-
t.decimal :value
|
141
|
-
end
|
142
|
-
model do
|
143
|
-
acts_as_resource
|
144
|
-
end
|
145
|
-
end
|
146
|
-
with_model :agent do
|
147
|
-
table do |t|
|
148
|
-
t.string :name
|
149
|
-
end
|
150
|
-
model do
|
151
|
-
acts_as_agent
|
152
|
-
end
|
153
|
-
end
|
154
|
-
with_model :increment_event do
|
155
|
-
table do |t|
|
156
|
-
t.references :resource
|
157
|
-
t.references :provider
|
158
|
-
t.decimal :amount
|
159
|
-
t.timestamps
|
160
|
-
end
|
161
|
-
model do
|
162
|
-
acts_as_event do
|
163
|
-
resource Resource
|
164
|
-
provider Agent
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
with_model :increment_commitment do
|
170
|
-
table do |t|
|
171
|
-
t.references :resource
|
172
|
-
t.references :provider
|
173
|
-
t.decimal :amount
|
174
|
-
t.boolean :fulfilled, :default=>false
|
175
|
-
t.timestamps
|
176
|
-
end
|
177
|
-
model do
|
178
|
-
acts_as_commitment do
|
179
|
-
resource Resource
|
180
|
-
provider Agent
|
181
|
-
event_creator IncrementEvent
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
let!(:entity_class) { IncrementCommitment }
|
186
|
-
include_examples "entities", [:resource, :amount, :provider ], {:resource_id=>1,:provider_id=>1,:amount=>1}
|
187
|
-
|
188
|
-
context :fulfill do
|
189
|
-
subject { IncrementCommitment }
|
190
|
-
its(:event_creator) { should == IncrementEvent }
|
191
|
-
end
|
192
|
-
|
193
|
-
context :callback do
|
194
|
-
subject { IncrementCommitment.new :resource_id=>1, :provider_id=>1, :amount=>1, :fulfilled=>true }
|
195
|
-
it :should_create_event do
|
196
|
-
expect {
|
197
|
-
subject.save
|
198
|
-
}.to change {IncrementEvent.count}
|
199
|
-
end
|
200
|
-
it :event_sum_amount_should_plus_when_fulfill do
|
201
|
-
expect {
|
202
|
-
subject.save
|
203
|
-
}.to change{IncrementEvent.sum(:amount)}.by(1)
|
204
|
-
end
|
205
|
-
it :event_sum_amount_should_minus_when_not_fulfill do
|
206
|
-
subject.save
|
207
|
-
subject.fulfilled = false
|
208
|
-
expect {
|
209
|
-
subject.save
|
210
|
-
}.to change{IncrementEvent.sum(:amount)}.by(-1)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context :acts_as_contract do
|
217
|
-
context :normal do
|
218
|
-
with_model :increment_commitment do
|
219
|
-
table do |t|
|
220
|
-
t.references :provider
|
221
|
-
t.references :resource
|
222
|
-
t.references :contract
|
223
|
-
t.decimal :amount
|
224
|
-
t.boolean :fulfilled
|
225
|
-
end
|
226
|
-
model do
|
227
|
-
acts_as_commitment do
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
with_model :decrement_commitment do
|
232
|
-
table do |t|
|
233
|
-
t.references :contract
|
234
|
-
end
|
235
|
-
model do
|
236
|
-
acts_as_commitment do
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
with_model :order do
|
241
|
-
table do |t|
|
242
|
-
end
|
243
|
-
model do
|
244
|
-
acts_as_contract do
|
245
|
-
clause IncrementCommitment
|
246
|
-
clause DecrementCommitment
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
context :sematics do
|
251
|
-
context :contract do
|
252
|
-
subject { Order }
|
253
|
-
its(:public_instance_methods) { should include :increment_commitments }
|
254
|
-
its(:public_instance_methods) { should include :decrement_commitments }
|
255
|
-
end
|
256
|
-
context :commitment do
|
257
|
-
subject { IncrementCommitment }
|
258
|
-
its(:public_instance_methods) { should include :contract }
|
259
|
-
end
|
260
|
-
end
|
261
|
-
context :model do
|
262
|
-
subject { Order.create }
|
263
|
-
it :could_add_increment_commitment do
|
264
|
-
expect { subject.increment_commitments.create :provider_id=>1, :resource_id=>1, :amount=>10
|
265
|
-
}.to change{IncrementCommitment.count}
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context :grouping do
|
272
|
-
with_model :entity do
|
273
|
-
table do |t|
|
274
|
-
t.string :name
|
275
|
-
end
|
276
|
-
model do
|
277
|
-
acts_as_resource do
|
278
|
-
grouping do
|
279
|
-
group_item :group_one, :group_two
|
280
|
-
group_item :group_three
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context :reflect_on_all_associations do
|
287
|
-
subject { Entity.reflect_on_all_associations.map(&:name) }
|
288
|
-
it { should include(:group_entities) }
|
289
|
-
it { should include(:groups) }
|
290
|
-
end
|
291
|
-
|
292
|
-
context :group_items do
|
293
|
-
subject { Rea::Group.groups(Entity).map(&:name) }
|
294
|
-
its(:size) { should == 3}
|
295
|
-
it { should include('group_one') }
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
end
|