ballast 1.5.3 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,14 @@ module Ballast
32
32
  def initialize(operations, context)
33
33
  @context = context
34
34
  @operations = operations.ensure_array
35
- setup
36
35
  end
36
+
37
+ private
38
+ # Returns the operations to perform.
39
+ #
40
+ # @return [Array] An array of operations to perform.
41
+ def interactors
42
+ @operations
43
+ end
37
44
  end
38
45
  end
@@ -13,10 +13,10 @@ module Ballast
13
13
  MAJOR = 1
14
14
 
15
15
  # The minor version.
16
- MINOR = 5
16
+ MINOR = 6
17
17
 
18
18
  # The patch version.
19
- PATCH = 3
19
+ PATCH = 0
20
20
 
21
21
  # The current version of ballast.
22
22
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -113,6 +113,18 @@ describe Ballast::Concerns::Ajax do
113
113
  "Access-Control-Max-Age" => "31557600"
114
114
  })
115
115
  end
116
+
117
+ it "should append custom headers values" do
118
+ subject.allow_cors(allow_origin: "ORIGIN", allow_methods: [:first, :second], allow_headers: "_", max_age: 1.day, allow_credentials: true)
119
+
120
+ expect(subject.headers).to eq({
121
+ "Access-Control-Allow-Origin" => "ORIGIN",
122
+ "Access-Control-Allow-Methods" => "FIRST, SECOND",
123
+ "Access-Control-Allow-Headers" => "_",
124
+ "Access-Control-Max-Age" => "86400",
125
+ "Access-Control-Allow-Credentials" => "true"
126
+ })
127
+ end
116
128
  end
117
129
 
118
130
  describe "#disallow_robots" do
@@ -57,6 +57,18 @@ describe Ballast::Concerns::Common do
57
57
  end
58
58
  end
59
59
 
60
+ describe "#perform_operations_chain" do
61
+ it "should perform the requested operation chain and memoize it" do
62
+ expect(Ballast::OperationsChain).to receive(:perform).with("OWNER", [:a, :b], a: 1, b: 2).and_return("OPERATION 1")
63
+ expect(Ballast::OperationsChain).to receive(:perform).with(subject, [:c, :d], c: 3, d: 4).and_return("OPERATION 2")
64
+
65
+ subject.perform_operations_chain([:a, :b], "OWNER", a: 1, b: 2)
66
+ expect(subject.instance_variable_get(:@operation)).to eq("OPERATION 1")
67
+ subject.perform_operations_chain([:c, :d], c: 3, d: 4)
68
+ expect(subject.instance_variable_get(:@operation)).to eq("OPERATION 2")
69
+ end
70
+ end
71
+
60
72
  describe "#format_short_duration" do
61
73
  it "should format a date" do
62
74
  now = DateTime.civil(2013, 12, 9, 15, 6, 00)
@@ -7,27 +7,55 @@ require "spec_helper"
7
7
 
8
8
  describe Ballast::OperationsChain do
9
9
  describe ".perform" do
10
- before(:each) do
11
- expect_any_instance_of(Ballast::OperationsChain).to receive(:perform)
10
+ class SuccessOperation < Ballast::Operation
11
+ def perform
12
+ response[:result] ||= 0
13
+ response[:result] += 1
14
+ end
12
15
  end
13
16
 
14
- it "should initialize with the set of operations and the first argument as context" do
15
- context = Ballast::Context.new
16
- expect(Ballast::Context).not_to receive(:build)
17
- expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
18
- Ballast::OperationsChain.perform(context, [:A, :B, :C])
17
+ class FailureOperation < Ballast::Operation
18
+ def perform
19
+ fail!
20
+ end
19
21
  end
20
22
 
21
- it "shuold use the provided owner and context" do
22
- context = Ballast::Context.new
23
- expect(Ballast::Context).not_to receive(:build)
24
- expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
25
- Ballast::OperationsChain.perform(nil, [:A, :B, :C], context: context)
23
+ class FinalOperation < Ballast::Operation
24
+ def perform
25
+ response[:result] = "#{response[:result]}F"
26
+ end
26
27
  end
27
28
 
28
- it "should created the context on the fly if needed" do
29
- expect(Ballast::Context).to receive(:build).with("A", {a: 1})
30
- Ballast::OperationsChain.perform("A", [:A, :B, :C], params: {a: 1})
29
+ describe ".perform" do
30
+ before(:each) do
31
+ expect_any_instance_of(Ballast::OperationsChain).to receive(:perform)
32
+ end
33
+
34
+ it "should initialize with the set of operations and the first argument as context" do
35
+ context = Ballast::Context.new
36
+ expect(Ballast::Context).not_to receive(:build)
37
+ expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
38
+ Ballast::OperationsChain.perform(context, [:A, :B, :C])
39
+ end
40
+
41
+ it "should use the provided owner and context" do
42
+ context = Ballast::Context.new
43
+ expect(Ballast::Context).not_to receive(:build)
44
+ expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
45
+ Ballast::OperationsChain.perform(nil, [:A, :B, :C], context: context)
46
+ end
47
+
48
+ it "should created the context on the fly if needed" do
49
+ expect(Ballast::Context).to receive(:build).with("A", {a: 1})
50
+ Ballast::OperationsChain.perform("A", [:A, :B, :C], params: {a: 1})
51
+ end
52
+ end
53
+
54
+ describe "#perform" do
55
+ it "should execute the operations unless they fail" do
56
+ expect(Ballast::OperationsChain.perform(nil, [SuccessOperation, FinalOperation]).response[:result]).to eq("1F")
57
+ expect(Ballast::OperationsChain.perform(nil, [SuccessOperation, FailureOperation, FinalOperation]).response[:result].to_s).not_to match(/F$/)
58
+ end
31
59
  end
32
60
  end
33
61
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-05 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
@@ -52,34 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.5.3
55
- - !ruby/object:Gem::Dependency
56
- name: lazier
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 3.3.10
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 3.3.10
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: brauser
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 3.2.4
61
+ version: 3.2.5
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 3.2.4
68
+ version: 3.2.5
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: interactor
85
71
  requirement: !ruby/object:Gem::Requirement