conderaction 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/conderaction/version.rb +1 -1
- data/lib/dci/context.rb +7 -7
- data/lib/dci/data.rb +3 -7
- data/test/context_test.rb +32 -3
- data/test/data_test.rb +5 -7
- data/test/test_helper.rb +35 -6
- metadata +26 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2225da0ea438e23d33846892ce9aaecf8cb25dc6
|
4
|
+
data.tar.gz: 25aceda1a6029dd3f1842cb6d310b22a22af3c7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ab394cac0ff8f64acf5ee055410fa924ae0282dce8e6334e90ee1e4b794a298cb788bdd14dddb52df5ae090210fa817e0fa2486688ed635022a719551923759
|
7
|
+
data.tar.gz: 2b92ddcaa278486729399d3c0302c16bfafc0d6ccd026a42b571350a2ec30bb2edb4e607008f511ceae461f0a19582e9eae399eb11da30c3ab668c388573390b
|
data/README.md
CHANGED
data/lib/conderaction/version.rb
CHANGED
data/lib/dci/context.rb
CHANGED
@@ -2,24 +2,24 @@ require 'casting'
|
|
2
2
|
require 'active_support'
|
3
3
|
|
4
4
|
module DCI
|
5
|
-
|
6
5
|
module Context
|
7
|
-
|
8
6
|
extend ActiveSupport::Concern
|
9
7
|
|
10
8
|
included do
|
11
|
-
def self.perform(*args)
|
12
|
-
|
9
|
+
def self.perform(*args, &block)
|
10
|
+
if block_given?
|
11
|
+
new.perform(*args, &block)
|
12
|
+
else
|
13
|
+
new.perform(*args)
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
def characterize(*args
|
18
|
+
def characterize(*args)
|
17
19
|
yield
|
18
20
|
args.each do |item|
|
19
21
|
item.uncast unless item.nil?
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
23
24
|
end
|
24
|
-
|
25
25
|
end
|
data/lib/dci/data.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'casting'
|
2
2
|
|
3
3
|
module DCI
|
4
|
-
|
5
4
|
module Data
|
6
|
-
|
7
5
|
extend ActiveSupport::Concern
|
8
6
|
|
9
7
|
included do
|
@@ -11,16 +9,14 @@ module DCI
|
|
11
9
|
delegate_missing_methods
|
12
10
|
end
|
13
11
|
|
14
|
-
def as(role
|
12
|
+
def as(role)
|
15
13
|
if block_given?
|
16
14
|
Casting.delegating(self => role) do
|
17
|
-
|
15
|
+
yield(self)
|
18
16
|
end
|
19
17
|
else
|
20
|
-
|
18
|
+
cast_as(role)
|
21
19
|
end
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
data/test/context_test.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'rspec/mocks'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class ContextTest < Minitest::Test
|
5
|
+
test "responds to added methods" do
|
6
|
+
data = test_person
|
7
|
+
context = test_greet
|
8
|
+
assert !data.respond_to?(:greet)
|
9
|
+
assert data.as(TestPerson::Greeter).respond_to?(:greet)
|
10
|
+
end
|
11
|
+
|
12
|
+
test "responds to added methods inside the block" do
|
6
13
|
data = test_person
|
7
14
|
context = test_greet
|
8
15
|
assert !data.respond_to?(:greet)
|
@@ -14,4 +21,26 @@ describe DCI::Context, '.characterize' do
|
|
14
21
|
assert !data.respond_to?(:greet)
|
15
22
|
end
|
16
23
|
|
24
|
+
test "will execute a perform directly" do
|
25
|
+
expect(TestAction).to receive(:perform)
|
26
|
+
TestAction.perform
|
27
|
+
end
|
28
|
+
|
29
|
+
test "will execute a yield on a perform" do
|
30
|
+
value = false
|
31
|
+
TestAction.perform do
|
32
|
+
value = true
|
33
|
+
end
|
34
|
+
|
35
|
+
assert value
|
36
|
+
end
|
37
|
+
|
38
|
+
test "will pass all the parameters through" do
|
39
|
+
params = nil
|
40
|
+
TestAction.perform(1, 2, 3) do |args|
|
41
|
+
params = args
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_equal [1, 2, 3], params
|
45
|
+
end
|
17
46
|
end
|
data/test/data_test.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it 'responds to added methods inside the block' do
|
3
|
+
class DataTest < Minitest::Test
|
4
|
+
test "responds to added methods inside the block" do
|
6
5
|
data = test_person
|
7
6
|
assert !data.respond_to?(:greet)
|
8
7
|
|
@@ -11,7 +10,7 @@ describe DCI::Data, '.as' do
|
|
11
10
|
assert !data.respond_to?(:greet)
|
12
11
|
end
|
13
12
|
|
14
|
-
|
13
|
+
test "responds to added methods without a block" do
|
15
14
|
data = test_person
|
16
15
|
assert !data.respond_to?(:greet)
|
17
16
|
|
@@ -20,7 +19,7 @@ describe DCI::Data, '.as' do
|
|
20
19
|
assert data.respond_to?(:greet)
|
21
20
|
end
|
22
21
|
|
23
|
-
|
22
|
+
test "returns results from added methods inside the block" do
|
24
23
|
data = test_person
|
25
24
|
assert_raises(NoMethodError) do
|
26
25
|
data.greet
|
@@ -31,7 +30,6 @@ describe DCI::Data, '.as' do
|
|
31
30
|
|
32
31
|
assert_raises(NoMethodError) do
|
33
32
|
data.greet
|
34
|
-
end
|
33
|
+
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,34 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'conderaction'
|
3
|
+
require 'rspec/mocks'
|
4
|
+
require 'minitest/rspec_mocks'
|
5
|
+
|
6
|
+
class Minitest::Test
|
7
|
+
include Minitest::RSpecMocks
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Helper to define a test method using a String. Under the hood, it replaces
|
11
|
+
# spaces with underscores and defines the test method.
|
12
|
+
#
|
13
|
+
# test "verify something" do
|
14
|
+
# ...
|
15
|
+
# end
|
16
|
+
def test(name, &block)
|
17
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
18
|
+
defined = method_defined? test_name
|
19
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
20
|
+
if block_given?
|
21
|
+
define_method(test_name, &block)
|
22
|
+
else
|
23
|
+
define_method(test_name) do
|
24
|
+
flunk "No implementation provided for #{name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
3
30
|
|
4
31
|
class TestPerson
|
5
|
-
|
6
32
|
include DCI::Data
|
7
33
|
|
8
34
|
def name
|
@@ -10,19 +36,14 @@ class TestPerson
|
|
10
36
|
end
|
11
37
|
|
12
38
|
module Greeter
|
13
|
-
|
14
39
|
def greet
|
15
40
|
'hello'
|
16
41
|
end
|
17
|
-
|
18
42
|
end
|
19
|
-
|
20
43
|
end
|
21
44
|
|
22
45
|
class TestGreet
|
23
|
-
|
24
46
|
include DCI::Context
|
25
|
-
|
26
47
|
end
|
27
48
|
|
28
49
|
def test_person
|
@@ -31,4 +52,12 @@ end
|
|
31
52
|
|
32
53
|
def test_greet
|
33
54
|
TestGreet.new
|
55
|
+
end
|
56
|
+
|
57
|
+
class TestAction
|
58
|
+
include DCI::Context
|
59
|
+
|
60
|
+
def perform(*args)
|
61
|
+
yield(args) if block_given?
|
62
|
+
end
|
34
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conderaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Palmer
|
@@ -9,22 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: casting
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0.7'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest-rspec_mocks
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
description: Allows you to follow DCI principles in Ruby on Rails
|
29
43
|
email:
|
30
44
|
- nathan@nathanpalmer.com
|
@@ -32,15 +46,15 @@ executables: []
|
|
32
46
|
extensions: []
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
35
51
|
- lib/conderaction.rb
|
52
|
+
- lib/conderaction/version.rb
|
36
53
|
- lib/dci/context.rb
|
37
54
|
- lib/dci/data.rb
|
38
|
-
- lib/conderaction/version.rb
|
39
|
-
- LICENSE
|
40
|
-
- README.md
|
41
|
-
- test/test_helper.rb
|
42
|
-
- test/data_test.rb
|
43
55
|
- test/context_test.rb
|
56
|
+
- test/data_test.rb
|
57
|
+
- test/test_helper.rb
|
44
58
|
homepage: https://github.com/sprucemail/conderaction
|
45
59
|
licenses:
|
46
60
|
- MIT
|
@@ -51,17 +65,17 @@ require_paths:
|
|
51
65
|
- lib
|
52
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
|
-
- -
|
68
|
+
- - ">="
|
55
69
|
- !ruby/object:Gem::Version
|
56
70
|
version: '2.0'
|
57
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
requirements: []
|
63
77
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.
|
78
|
+
rubygems_version: 2.2.2
|
65
79
|
signing_key:
|
66
80
|
specification_version: 4
|
67
81
|
summary: DCI for Ruby on Rails
|