playhouse 0.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +69 -0
- data/README.md +207 -0
- data/Rakefile +16 -0
- data/lib/playhouse/context.rb +120 -0
- data/lib/playhouse/part.rb +29 -0
- data/lib/playhouse/play.rb +59 -0
- data/lib/playhouse/production.rb +33 -0
- data/lib/playhouse/role.rb +55 -0
- data/lib/playhouse/scouts/build_with_composer.rb +33 -0
- data/lib/playhouse/scouts/can_construct_object.rb +15 -0
- data/lib/playhouse/scouts/direct_value.rb +9 -0
- data/lib/playhouse/scouts/entity_from_repository.rb +23 -0
- data/lib/playhouse/support/default_hash_values.rb +23 -0
- data/lib/playhouse/support/files.rb +7 -0
- data/lib/playhouse/talent_scout.rb +42 -0
- data/lib/playhouse/theatre.rb +62 -0
- data/lib/playhouse/validation/actors_validator.rb +23 -0
- data/lib/playhouse/validation/required_actor_validator.rb +17 -0
- data/lib/playhouse/validation/validation_errors.rb +76 -0
- data/playhouse.gemspec +20 -0
- data/spec/playhouse/context_spec.rb +111 -0
- data/spec/playhouse/part_spec.rb +19 -0
- data/spec/playhouse/play_spec.rb +64 -0
- data/spec/playhouse/production_spec.rb +47 -0
- data/spec/playhouse/role_spec.rb +72 -0
- data/spec/playhouse/support/default_hash_values_spec.rb +34 -0
- data/spec/playhouse/talent_scout_spec.rb +95 -0
- data/spec/playhouse/theatre_spec.rb +34 -0
- data/spec/playhouse/validation/actors_validator_spec.rb +38 -0
- data/spec/spec_helper.rb +5 -0
- metadata +133 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'playhouse/talent_scout'
|
3
|
+
require 'playhouse/context'
|
4
|
+
|
5
|
+
module Playhouse
|
6
|
+
describe TalentScout do
|
7
|
+
context "for a context with a single actor" do
|
8
|
+
subject { TalentScout.new }
|
9
|
+
let(:actor) { double(:actor) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
@context_class = Class.new(Context)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "build_context_with_parent" do
|
16
|
+
before do
|
17
|
+
@parent = double(:context)
|
18
|
+
@child = double(:context, inherit_actors_from: nil)
|
19
|
+
subject.stub(:build_context).and_return(@child)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'wraps build_context' do
|
23
|
+
expect(subject).to receive(:build_context).with(@context_class, {})
|
24
|
+
subject.build_context_with_parent @parent, @context_class, {}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'calls inherit_actors on the child' do
|
28
|
+
expect(@child).to receive(:inherit_actors_from).with(@parent)
|
29
|
+
subject.build_context_with_parent @parent, @context_class, {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "which is an entity" do
|
34
|
+
let(:entity_repository) { double(:repository) }
|
35
|
+
|
36
|
+
context "with a repository specified" do
|
37
|
+
before do
|
38
|
+
@context_class.actor :source_account, repository: entity_repository
|
39
|
+
end
|
40
|
+
|
41
|
+
it "finds the entity using the supplied id" do
|
42
|
+
entity_repository.should_receive(:find).with('2').and_return(actor)
|
43
|
+
context = subject.build_context(@context_class, :source_account_id => '2')
|
44
|
+
context.source_account.should == actor
|
45
|
+
end
|
46
|
+
|
47
|
+
it "finds no entity if no id is supplied" do
|
48
|
+
context = subject.build_context(@context_class, :some_other_id => '2')
|
49
|
+
context.source_account.should == nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "uses the entity itself if it is supplied" do
|
53
|
+
context = subject.build_context(@context_class, :source_account => actor)
|
54
|
+
context.source_account.should == actor
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "without a repository specified" do
|
59
|
+
before do
|
60
|
+
@context_class.actor :source_account
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not find the entity" do
|
64
|
+
context = subject.build_context(@context_class, :source_account_id => '2')
|
65
|
+
context.source_account.should == nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "uses the entity itself if it is supplied" do
|
69
|
+
context = subject.build_context(@context_class, :source_account => actor)
|
70
|
+
context.source_account.should == actor
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "which is a non persisted object" do
|
76
|
+
context "with a composer specified" do
|
77
|
+
let(:composer) { double(:composer) }
|
78
|
+
|
79
|
+
before do
|
80
|
+
@context_class.actor(:source_account, composer: composer)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "allows the composer to build the object from it's attributes" do
|
84
|
+
params = {source_account: 'Fred Savings'}
|
85
|
+
composer.should_receive(:compose).with('Fred Savings').and_return(actor)
|
86
|
+
|
87
|
+
context = subject.build_context(@context_class, params)
|
88
|
+
|
89
|
+
context.source_account.should == actor
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'playhouse/theatre'
|
3
|
+
|
4
|
+
module Playhouse
|
5
|
+
describe Theatre do
|
6
|
+
def test_theatre
|
7
|
+
Theatre.new({environment: 'test', load_db: false})
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { test_theatre }
|
11
|
+
|
12
|
+
after do
|
13
|
+
Theatre.clear_current
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".current" do
|
17
|
+
it "is set to this theatre if you open the theatre" do
|
18
|
+
subject.open
|
19
|
+
Theatre.current.should == subject
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is cleared if you close" do
|
23
|
+
subject.open
|
24
|
+
subject.close
|
25
|
+
Theatre.current.should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises an error if there is already something else open" do
|
29
|
+
test_theatre.open
|
30
|
+
expect { subject.open }.to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'playhouse/validation/actors_validator'
|
3
|
+
|
4
|
+
module Playhouse
|
5
|
+
describe ActorsValidator do
|
6
|
+
let(:part) { double(:part, name: :foobar, validators: []) }
|
7
|
+
|
8
|
+
describe "#validate_actors" do
|
9
|
+
it "does nothing part has no validators" do
|
10
|
+
subject.validate_actors([part], {amount: 1})
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with invalid fields" do
|
14
|
+
before do
|
15
|
+
invalid_validator = double(:validator)
|
16
|
+
invalid_validator.should_receive(:validate_actor).with(123).and_raise(RequiredActorMissing.new(part_name: :foobar))
|
17
|
+
part.stub(validators: [invalid_validator])
|
18
|
+
end
|
19
|
+
|
20
|
+
it "raises exception if the part has a validator which raises an exception" do
|
21
|
+
expect {
|
22
|
+
subject.validate_actors([part], {foobar: 123})
|
23
|
+
}.to raise_error(ContextValidationError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "includes the details of all invalid fields in the exception" do
|
27
|
+
begin
|
28
|
+
subject.validate_actors([part], {foobar: 123})
|
29
|
+
rescue ContextValidationError => error
|
30
|
+
part_error = error.for_part(:foobar).first
|
31
|
+
part_error.should be_a(RequiredActorMissing)
|
32
|
+
part_error.part_name.should == :foobar
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: playhouse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Craig Ambrose
|
8
|
+
- Joshua Vial
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: activerecord
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Provides one possible way of implementing a DCI architecture in a ruby
|
57
|
+
app
|
58
|
+
email:
|
59
|
+
- craig@enspiral.com
|
60
|
+
- joshua@enspiral.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .ruby-version
|
67
|
+
- .travis.yml
|
68
|
+
- CHANGELOG.md
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/playhouse/context.rb
|
74
|
+
- lib/playhouse/part.rb
|
75
|
+
- lib/playhouse/play.rb
|
76
|
+
- lib/playhouse/production.rb
|
77
|
+
- lib/playhouse/role.rb
|
78
|
+
- lib/playhouse/scouts/build_with_composer.rb
|
79
|
+
- lib/playhouse/scouts/can_construct_object.rb
|
80
|
+
- lib/playhouse/scouts/direct_value.rb
|
81
|
+
- lib/playhouse/scouts/entity_from_repository.rb
|
82
|
+
- lib/playhouse/support/default_hash_values.rb
|
83
|
+
- lib/playhouse/support/files.rb
|
84
|
+
- lib/playhouse/talent_scout.rb
|
85
|
+
- lib/playhouse/theatre.rb
|
86
|
+
- lib/playhouse/validation/actors_validator.rb
|
87
|
+
- lib/playhouse/validation/required_actor_validator.rb
|
88
|
+
- lib/playhouse/validation/validation_errors.rb
|
89
|
+
- playhouse.gemspec
|
90
|
+
- spec/playhouse/context_spec.rb
|
91
|
+
- spec/playhouse/part_spec.rb
|
92
|
+
- spec/playhouse/play_spec.rb
|
93
|
+
- spec/playhouse/production_spec.rb
|
94
|
+
- spec/playhouse/role_spec.rb
|
95
|
+
- spec/playhouse/support/default_hash_values_spec.rb
|
96
|
+
- spec/playhouse/talent_scout_spec.rb
|
97
|
+
- spec/playhouse/theatre_spec.rb
|
98
|
+
- spec/playhouse/validation/actors_validator_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: https://github.com/enspiral/economatic
|
101
|
+
licenses: []
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.9.2
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.3
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: A DCI framework
|
123
|
+
test_files:
|
124
|
+
- spec/playhouse/context_spec.rb
|
125
|
+
- spec/playhouse/part_spec.rb
|
126
|
+
- spec/playhouse/play_spec.rb
|
127
|
+
- spec/playhouse/production_spec.rb
|
128
|
+
- spec/playhouse/role_spec.rb
|
129
|
+
- spec/playhouse/support/default_hash_values_spec.rb
|
130
|
+
- spec/playhouse/talent_scout_spec.rb
|
131
|
+
- spec/playhouse/theatre_spec.rb
|
132
|
+
- spec/playhouse/validation/actors_validator_spec.rb
|
133
|
+
- spec/spec_helper.rb
|