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.
Files changed (75) hide show
  1. data/VERSION +1 -1
  2. data/app/models/rea/category.rb +4 -0
  3. data/app/models/rea/category_member.rb +1 -0
  4. data/app/models/rea/category_type.rb +1 -1
  5. data/app/models/rea/group.rb +17 -6
  6. data/app/models/rea/group_type.rb +7 -0
  7. data/app/models/rea/identifier.rb +12 -3
  8. data/config/locales/en.yml +4 -0
  9. data/config/locales/zh-CN.yml +42 -0
  10. data/db/migrate/20120601074531_create_rea_category_types.rb +1 -1
  11. data/db/migrate/20120601074540_create_rea_categories.rb +1 -1
  12. data/db/migrate/20120605030658_create_rea_groups.rb +14 -3
  13. data/db/migrate/20120605082028_create_rea_identifiers.rb +2 -2
  14. data/db/migrate/20120717080004_create_rea_group_types.rb +7 -0
  15. data/engine-rea.gemspec +31 -14
  16. data/lib/generators/rea/install/install_generator.rb +8 -0
  17. data/lib/rails_patch.rb +26 -0
  18. data/lib/rea.rb +25 -1
  19. data/lib/rea/application.rb +86 -0
  20. data/lib/rea/aspect_type.rb +28 -6
  21. data/lib/rea/aspect_type/base.rb +3 -2
  22. data/lib/rea/aspect_type/classification.rb +142 -0
  23. data/lib/rea/aspect_type/description.rb +3 -2
  24. data/lib/rea/aspect_type/due_date.rb +34 -0
  25. data/lib/rea/aspect_type/identification.rb +38 -0
  26. data/lib/rea/engine.rb +1 -3
  27. data/lib/rea/meta_type.rb +1 -1
  28. data/lib/rea/meta_type/agent.rb +1 -1
  29. data/lib/rea/meta_type/commitment.rb +5 -6
  30. data/lib/rea/meta_type/contract.rb +17 -4
  31. data/lib/rea/meta_type/conversion.rb +6 -0
  32. data/lib/rea/meta_type/entity.rb +61 -20
  33. data/lib/rea/meta_type/event.rb +17 -24
  34. data/lib/rea/meta_type/exchange.rb +6 -0
  35. data/lib/rea/meta_type/group.rb +25 -0
  36. data/lib/rea/meta_type/process.rb +28 -0
  37. data/lib/rea/meta_type/resource.rb +5 -1
  38. data/lib/rea/model.rb +65 -0
  39. data/lib/rea/settings.rb +58 -0
  40. data/spec/dummy/db/schema.rb +1 -56
  41. data/spec/generators/rea/install/install_generator_spec.rb +2 -0
  42. data/spec/models/rea/category_member_spec.rb +5 -1
  43. data/spec/models/rea/category_spec.rb +19 -1
  44. data/spec/models/rea/category_type_spec.rb +24 -1
  45. data/spec/models/rea/group_spec.rb +34 -1
  46. data/spec/models/rea/group_type_spec.rb +8 -0
  47. data/spec/rea/application_spec.rb +8 -0
  48. data/spec/rea/aspect_type/classification_spec.rb +107 -0
  49. data/spec/rea/aspect_type/due_date_spec.rb +75 -0
  50. data/spec/rea/aspect_type/identification_spec.rb +64 -0
  51. data/spec/rea/aspect_type_spec.rb +44 -0
  52. data/spec/rea/engine_spec.rb +0 -3
  53. data/spec/rea/meta_type/agent_spec.rb +28 -0
  54. data/spec/rea/meta_type/commitment_spec.rb +45 -0
  55. data/spec/rea/meta_type/contract_spec.rb +42 -0
  56. data/spec/rea/meta_type/entity_spec.rb +58 -0
  57. data/spec/rea/meta_type/event_spec.rb +21 -0
  58. data/spec/rea/meta_type/group_spec.rb +55 -0
  59. data/spec/rea/meta_type/process_spec.rb +5 -0
  60. data/spec/rea/meta_type/resource_spec.rb +65 -0
  61. data/spec/rea/meta_type_spec.rb +1 -1
  62. data/spec/rea/model_spec.rb +79 -0
  63. metadata +32 -15
  64. data/app/models/rea/group_entity.rb +0 -7
  65. data/db/migrate/20120605030708_create_rea_group_entities.rb +0 -9
  66. data/lib/rea/aspect_type/classification_aspect.rb +0 -75
  67. data/lib/rea/aspect_type/due_date_type.rb +0 -5
  68. data/lib/rea/aspect_type/identifier_setup.rb +0 -7
  69. data/lib/rea/dsl.rb +0 -24
  70. data/lib/rea/dsl/behavioral.rb +0 -50
  71. data/lib/rea/dsl/structural.rb +0 -53
  72. data/spec/models/rea/group_entity_spec.rb +0 -5
  73. data/spec/rea/dsl/behavioral_spec.rb +0 -149
  74. data/spec/rea/dsl/structural_spec.rb +0 -299
  75. data/spec/rea/dsl_spec.rb +0 -11
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::Application do
4
+
5
+ subject { Rea.application }
6
+
7
+ its(:load_paths) { should have(1).items }
8
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::AspectType::Classification do
4
+ let(:category_type) { Rea::CategoryType.create :name=>:category_type }
5
+ let(:category_type_multi) { Rea::CategoryType.create :name=>:category_type_multi }
6
+
7
+ before :all do
8
+ category_type.category :cate_l1_1, :cate_l1_2
9
+ category_type.category :cate_l1_3 do
10
+ category :cate_l2_1, :cate_l2_2
11
+ end
12
+ category_type_multi.category :catem_l1_1, :catem_l1_2
13
+ category_type_multi.category :catem_l1_3 do
14
+ category :catem_l2_1, :catem_l2_2
15
+ end
16
+ end
17
+
18
+
19
+ context :syntax_symbol_table_classification_aspect do
20
+ with_model :resource do
21
+ table do |t|
22
+ t.string :name
23
+ t.decimal :value
24
+ t.references :member_type
25
+ end
26
+ model do
27
+ end
28
+ end
29
+
30
+ before :each do
31
+ Rea.model do
32
+ entities do
33
+ resource :resource do
34
+ classification :auto_classification=>false do
35
+ member :member_type, :multiple_select=>false do
36
+ category :category_type
37
+ end
38
+ member :member_type_multi, :multiple_select=>true do
39
+ category :category_type_multi
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+ subject { Rea.context.symbol_table[:resource_classification_aspect] }
49
+ it { should_not be_nil }
50
+ it { should be_a_kind_of Rea::AspectType::Classification::Aspect }
51
+ its(:members) { should have(2).items }
52
+ it { subject.member_type_for(:category_type).should == :member_type }
53
+ it { subject.member_type_for(:category_type_multi).should == :member_type_multi }
54
+
55
+ context :members do
56
+ subject { Rea.context.symbol_table[:resource_classification_aspect].members[:member_type_multi] }
57
+ its(:multiple_select) { should be_true }
58
+ end
59
+
60
+ context :model do
61
+ let(:category) { ::Rea::Category.find_by_name :cate_l1_1 }
62
+
63
+ context :class do
64
+ before :each do
65
+ Resource.delete_all
66
+ 10.times do
67
+ Resource.create! :name=>:name, :value=>10, :member_type_id=>category.id
68
+ end
69
+ end
70
+ subject { Resource }
71
+ it { subject.by_category(category).size.should == 10 }
72
+ it { subject.categories_for(:member_type).size.should == 5 }
73
+ end
74
+
75
+ context :instance do
76
+ subject { Resource.create! :name=>:name, :value=>1, :member_type_id=>category.id }
77
+ it { subject.is?(category).should be_true }
78
+ it { subject.is_in?(category).should be_true }
79
+ end
80
+
81
+ context :instance_multi do
82
+ let(:resource_multi) do
83
+ ids = Rea::CategoryType.find_by_name(:category_type_multi).category_ids
84
+ Resource.create! :name=>:name, :value=>1, :member_type_multi_ids=> ids
85
+ end
86
+
87
+ subject { resource_multi }
88
+
89
+ its(:member_type_multi) { should have(5).items }
90
+
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ context :category_type_and_category do
97
+
98
+ context :category_type do
99
+ subject { category_type }
100
+ its(:categories) { should have(5).items }
101
+ context :category do
102
+ subject{ Rea::Category.find_by_name 'cate_l1_3' }
103
+ its(:child_categories) { should have(2).items }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::AspectType::DueDate do
4
+
5
+ with_model :resource do
6
+ table do |t|
7
+ t.string :name
8
+ t.decimal :value
9
+ t.datetime :deadline
10
+ end
11
+ model do
12
+ end
13
+ end
14
+
15
+ before :each do
16
+ Rea.model do
17
+ entities do
18
+ resource :resource do
19
+ due_date do
20
+ member :deadline, :editable=>true
21
+ member :auto_date, :editable=>false, :activation_rule=>proc{Time.now}
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ context :syntax do
29
+ context :aspect do
30
+ subject { Rea.context.symbol_table[:resource_due_date_aspect] }
31
+ it(:member) { subject.respond_to?(:member).should be_true }
32
+ end
33
+ context :entity_class do
34
+ subject { Resource }
35
+ it(:expired_on){ subject.respond_to?(:expired_on).should be_true }
36
+ it(:active_on){ subject.respond_to?(:active_on).should be_true }
37
+
38
+ context :with_data do
39
+ before :each do
40
+ subject.delete_all
41
+ 10.times do
42
+ subject.create :name=>:name1, :value=>1, :deadline=>1.days.ago
43
+ subject.create :name=>:name2, :value=>1, :deadline=>1.days.from_now
44
+ end
45
+ end
46
+
47
+ it :active_and_expired do
48
+ subject.count.should == 20
49
+ subject.active_on(:deadline).size.should == 10
50
+ subject.expired_on(:deadline).size.should == 10
51
+ end
52
+
53
+ end
54
+ end
55
+ context :entity_instance do
56
+ subject { Resource.new }
57
+ its(:public_methods) { should include :deadline, :deadline_state, :deadline_expired? }
58
+ end
59
+ end
60
+
61
+ context :model do
62
+ context :active do
63
+ subject { Resource.new :deadline=> 1.days.from_now }
64
+ its(:deadline_state) { should == :active }
65
+ its(:deadline_expired?) { should be_false }
66
+ end
67
+ context :expired do
68
+ subject { Resource.new :deadline=> 1.days.ago }
69
+ its(:deadline_state) { should == :expired }
70
+ its(:deadline_expired?) { should be_true }
71
+ end
72
+ end
73
+ end
74
+
75
+
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::AspectType::Identification do
4
+
5
+ def valid_attributes
6
+ {:name=>:name, :value=>1}
7
+ end
8
+
9
+ with_model :resource do
10
+ table do |t|
11
+ t.string :name
12
+ t.decimal :value
13
+ t.string :sn
14
+ t.string :sn_other
15
+ end
16
+ model do
17
+ end
18
+ end
19
+
20
+ before :each do
21
+ Rea.model do
22
+ entities do
23
+ resource :resource do
24
+ identification do
25
+ identifier :sn
26
+ identifier :sn_other, :type=>"resource.sn2"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ context :syntax do
34
+ subject { Rea.context.symbol_table[:resource_identification_aspect] }
35
+ its(:identifiers) { should have(2).items }
36
+ it(:default_type) { subject.identifiers[:sn].type.should == "resource.sn" }
37
+ it(:customize_type) { subject.identifiers[:sn_other].type.should == 'resource.sn2'}
38
+ end
39
+
40
+ context :callback do
41
+ before :each do
42
+ Rea::Identifier.delete_all
43
+ Rea::Identifier.create :name=>"resource.sn", :id_rule=>"RESOURCE_SN"
44
+ Rea::Identifier.create :name=>"resource.sn2", :id_rule=>"RESOUCE_SN2"
45
+ end
46
+
47
+ context :update do
48
+ let(:resource) { Resource.create! valid_attributes }
49
+ subject { resource }
50
+ before(:each) { resource.save }
51
+ it { should be_valid }
52
+ it { should_not be_sn_changed }
53
+ end
54
+
55
+ context :create do
56
+ subject { Resource.create! valid_attributes }
57
+ before(:each) { subject.reload }
58
+ its(:sn) { should == "RESOURCE_SN" }
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::AspectType do
4
+
5
+ with_model :resource do
6
+ table do |t|
7
+ t.string :name
8
+ t.decimal :value
9
+ end
10
+ model do
11
+ end
12
+ end
13
+
14
+ before :each do
15
+ Rea.model do
16
+ entities do
17
+ resource :resource
18
+ end
19
+ end
20
+ end
21
+
22
+ def valid_attributes
23
+ {:name=>:name, :value=>1}
24
+ end
25
+
26
+ context :syntax do
27
+ subject { Resource }
28
+
29
+ %W{classification identification description due_date}.each do |method|
30
+ context "#{method}_context" do
31
+ before(:each) do
32
+ subject.send method, :name
33
+ end
34
+ it("respond_to? #{method}"){ subject.respond_to?(method).should be_true }
35
+ it("block called #{method}") do
36
+ expect { |b| subject.send(method,:"#{method}_aspect", &b) }.to yield_control
37
+ end
38
+ its("ancestors") { should include "Rea::AspectType::#{method.camelize}".constantize }
39
+ its("#{method}_aspect") { should be_a_kind_of "Rea::AspectType::#{method.camelize}::Aspect".constantize }
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -3,8 +3,5 @@ require 'spec_helper'
3
3
  describe Rea::Engine do
4
4
 
5
5
  context :initialize do
6
- it :monkey_patch_active_record do
7
- ActiveRecord::Base.included_modules.should include(Rea::Dsl)
8
- end
9
6
  end
10
7
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::MetaType::Agent do
4
+
5
+ context :active_record_resource_define do
6
+ with_model :agent do
7
+ table do |t|
8
+ t.string :name
9
+ end
10
+ end
11
+
12
+ before(:each) do
13
+ Rea.model do
14
+ entities do
15
+ agent :agent
16
+ end
17
+ end
18
+ end
19
+
20
+ subject { Agent.new :name=>:name }
21
+ it { should be_valid }
22
+ it :name_not_nil do
23
+ subject.name = nil
24
+ should_not be_valid
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::MetaType::Commitment do
4
+
5
+ with_model :commitment do
6
+ table do |t|
7
+ t.references :provider
8
+ t.references :resource
9
+ t.decimal :amount
10
+ t.boolean :fulfilled
11
+ end
12
+ model do
13
+ end
14
+ end
15
+
16
+ before(:each) do
17
+ Rea.model do
18
+ entities do
19
+ commitment :commitment, :type=>:increment do
20
+ event_creator do
21
+ raise :callback
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ context :syntax do
30
+ subject { Rea.context.symbol_table[:commitment] }
31
+ its(:ancestors) { should include Rea::MetaType::Commitment }
32
+ its(:event_handler) {should_not be_nil }
33
+ end
34
+
35
+ context :model do
36
+ subject { Commitment.new :amount=>1 }
37
+ it {
38
+ expect do |b|
39
+ Commitment.event_creator &b
40
+ subject.fulfilled = true
41
+ subject.save
42
+ end.to yield_control
43
+ }
44
+ end
45
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::MetaType::Contract do
4
+
5
+ with_model :contract do
6
+ table do |t|
7
+ end
8
+ model do
9
+ end
10
+ end
11
+ with_model :agent do
12
+
13
+ end
14
+ with_model :commitment do
15
+ table do
16
+ end
17
+ model do
18
+ end
19
+ end
20
+
21
+ before(:each) do
22
+ Rea.model do
23
+ entities do
24
+ agent :agent
25
+ commitment :commitment
26
+ contract :contract do
27
+ clause :commitment
28
+ party :buyer, Agent
29
+ party :seller, :agent
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ context :syntax do
36
+ subject { Rea.context.symbol_table[:contract] }
37
+ it { should_not be_nil }
38
+ its(:clauses) { should include Commitment }
39
+ its(:reflect_on_all_associations) { should have(3).items }
40
+ end
41
+
42
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rea::MetaType::Entity do
4
+
5
+ with_model :agent do
6
+ table do |t|
7
+ t.string :name
8
+ t.references :group
9
+ end
10
+ end
11
+
12
+ with_model :group do
13
+ table do |t|
14
+ t.string :name
15
+ end
16
+ end
17
+
18
+ before :each do
19
+ Rea.model do
20
+ entities do
21
+ group :group
22
+ agent :agent do
23
+ grouping :group
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ context :syntax do
30
+ subject { Rea.context.symbol_table[:agent] }
31
+ it { should == Agent }
32
+ context :group_reflect do
33
+ subject { Agent.reflect_on_association(:group) }
34
+ it { should_not be_nil }
35
+ its(:macro) { should == :belongs_to }
36
+ end
37
+
38
+ end
39
+
40
+ context :model do
41
+ before :each do
42
+ Agent.delete_all
43
+ Group.delete_all
44
+ Group.create! :name=>:group
45
+ 2.times do
46
+ Agent.create! :name=>:agent, :group_id=>Group.last.id
47
+ end
48
+ end
49
+ context :class do
50
+ subject { Agent }
51
+ it :groups_for do
52
+ subject.groups_for(:group).should have(1).items
53
+ end
54
+
55
+ end
56
+ end
57
+
58
+ end