light-service 0.17.0 → 0.19.0

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/project-build.yml +3 -6
  3. data/.rubocop.yml +117 -3
  4. data/README.md +101 -31
  5. data/RELEASES.md +11 -0
  6. data/lib/generators/light_service/generator_utils.rb +0 -2
  7. data/lib/light-service/action.rb +3 -5
  8. data/lib/light-service/configuration.rb +10 -2
  9. data/lib/light-service/context/key_verifier.rb +4 -2
  10. data/lib/light-service/context.rb +10 -15
  11. data/lib/light-service/deprecation_warning.rb +17 -0
  12. data/lib/light-service/errors.rb +4 -0
  13. data/lib/light-service/i18n/localization_adapter.rb +46 -0
  14. data/lib/light-service/localization_adapter.rb +14 -27
  15. data/lib/light-service/localization_map.rb +7 -0
  16. data/lib/light-service/orchestrator.rb +3 -3
  17. data/lib/light-service/organizer/reduce_case.rb +48 -0
  18. data/lib/light-service/organizer/verify_call_method_exists.rb +1 -1
  19. data/lib/light-service/organizer/with_reducer.rb +6 -8
  20. data/lib/light-service/organizer/with_reducer_log_decorator.rb +2 -2
  21. data/lib/light-service/organizer.rb +5 -3
  22. data/lib/light-service/testing/context_factory.rb +4 -0
  23. data/lib/light-service/version.rb +1 -1
  24. data/lib/light-service.rb +5 -2
  25. data/light-service.gemspec +3 -6
  26. data/spec/acceptance/after_actions_spec.rb +3 -9
  27. data/spec/acceptance/before_actions_spec.rb +3 -9
  28. data/spec/acceptance/include_warning_spec.rb +2 -2
  29. data/spec/acceptance/message_localization_spec.rb +7 -7
  30. data/spec/acceptance/not_having_call_method_warning_spec.rb +3 -3
  31. data/spec/acceptance/organizer/reduce_case_spec.rb +53 -0
  32. data/spec/acceptance/organizer/reduce_if_spec.rb +2 -0
  33. data/spec/acceptance/skip_all_warning_spec.rb +1 -1
  34. data/spec/context/inspect_spec.rb +5 -21
  35. data/spec/context_spec.rb +2 -2
  36. data/spec/i18n_localization_adapter_spec.rb +83 -0
  37. data/spec/lib/generators/action_generator_advanced_spec.rb +1 -1
  38. data/spec/lib/generators/action_generator_simple_spec.rb +1 -1
  39. data/spec/lib/generators/organizer_generator_advanced_spec.rb +1 -1
  40. data/spec/lib/generators/organizer_generator_simple_spec.rb +1 -1
  41. data/spec/localization_adapter_spec.rb +17 -38
  42. data/spec/sample/calculates_tax_spec.rb +0 -1
  43. data/spec/sample/looks_up_tax_percentage_action_spec.rb +3 -1
  44. data/spec/support.rb +1 -1
  45. data/spec/test_doubles.rb +20 -5
  46. data/spec/testing/context_factory_spec.rb +15 -0
  47. metadata +19 -42
  48. data/Appraisals +0 -11
  49. data/gemfiles/activesupport_5.gemfile +0 -7
  50. data/gemfiles/activesupport_6.gemfile +0 -7
@@ -114,9 +114,9 @@ module LightService
114
114
  end
115
115
 
116
116
  def issue_deprecation_warning_for(method_name)
117
- msg = "`Orchestrator##{method_name}` is DEPRECATED and will be " \
118
- "removed, please switch to `Organizer##{method_name} instead. "
119
- ActiveSupport::Deprecation.warn(msg)
117
+ warning_msg = "`Orchestrator##{method_name}` is DEPRECATED and will be " \
118
+ "removed, please switch to `Organizer##{method_name} instead. "
119
+ LightService::Deprecation.warn(warning_msg)
120
120
  end
121
121
  end
122
122
  end
@@ -0,0 +1,48 @@
1
+ module LightService
2
+ module Organizer
3
+ class ReduceCase
4
+ extend ScopedReducable
5
+
6
+ class Arguments
7
+ attr_reader :value, :when, :else
8
+
9
+ def initialize(**args)
10
+ validate_arguments(**args)
11
+ @value = args[:value]
12
+ @when = args[:when]
13
+ @else = args[:else]
14
+ end
15
+
16
+ private
17
+
18
+ # rubocop:disable Style/MultilineIfModifier
19
+ def validate_arguments(**args)
20
+ raise(
21
+ ArgumentError,
22
+ "Expected keyword arguments: [:value, :when, :else]. Given: #{args.keys}"
23
+ ) unless args.keys.intersection(mandatory_arguments).count == mandatory_arguments.count
24
+ end
25
+ # rubocop:enable Style/MultilineIfModifier
26
+
27
+ def mandatory_arguments
28
+ %i[value when else]
29
+ end
30
+ end
31
+
32
+ def self.run(organizer, **args)
33
+ arguments = Arguments.new(**args)
34
+
35
+ lambda do |ctx|
36
+ return ctx if ctx.stop_processing?
37
+
38
+ matched_case = arguments.when.keys.find { |k| k.eql?(ctx[arguments.value]) }
39
+ steps = arguments.when[matched_case] || arguments.else
40
+
41
+ ctx = scoped_reduce(organizer, ctx, steps)
42
+
43
+ ctx
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -15,7 +15,7 @@ module LightService
15
15
  "its entry method (the one that calls with & reduce) " \
16
16
  "should be named `call`. " \
17
17
  "Please use #{klass}.call going forward."
18
- ActiveSupport::Deprecation.warn(warning_msg)
18
+ LightService.deprecation_warning(warning_msg)
19
19
  end
20
20
 
21
21
  def self.caller_method(first_caller)
@@ -34,14 +34,12 @@ module LightService
34
34
  actions.flatten!
35
35
 
36
36
  actions.each_with_object(context) do |action, current_context|
37
- begin
38
- invoke_action(current_context, action)
39
- rescue FailWithRollbackError
40
- reduce_rollback(actions)
41
- ensure
42
- # For logging
43
- yield(current_context, action) if block_given?
44
- end
37
+ invoke_action(current_context, action)
38
+ rescue FailWithRollbackError
39
+ reduce_rollback(actions)
40
+ ensure
41
+ # For logging
42
+ yield(current_context, action) if block_given?
45
43
  end
46
44
  end
47
45
 
@@ -5,7 +5,7 @@ module LightService
5
5
 
6
6
  alias logged? logged
7
7
 
8
- def initialize(organizer, decorated: WithReducer.new, logger:)
8
+ def initialize(organizer, logger:, decorated: WithReducer.new)
9
9
  @decorated = decorated
10
10
  @organizer = organizer
11
11
 
@@ -22,7 +22,7 @@ module LightService
22
22
 
23
23
  logger.info do
24
24
  "[LightService] - keys in context: " \
25
- "#{extract_keys(decorated.context.keys)}"
25
+ "#{extract_keys(decorated.context.keys)}"
26
26
  end
27
27
  self
28
28
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/deprecation'
2
-
3
1
  module LightService
4
2
  module Organizer
5
3
  def self.extended(base_class)
@@ -10,7 +8,7 @@ module LightService
10
8
  def self.included(base_class)
11
9
  warning_msg = "including LightService::Organizer is deprecated. " \
12
10
  "Please use `extend LightService::Organizer` instead"
13
- ActiveSupport::Deprecation.warn(warning_msg)
11
+ LightService::Deprecation.warn(warning_msg)
14
12
  extended(base_class)
15
13
  end
16
14
 
@@ -49,6 +47,10 @@ module LightService
49
47
  ReduceUntil.run(self, condition_block, steps)
50
48
  end
51
49
 
50
+ def reduce_case(**args)
51
+ ReduceCase.run(self, **args)
52
+ end
53
+
52
54
  def iterate(collection_key, steps)
53
55
  Iterate.run(self, collection_key, steps)
54
56
  end
@@ -26,11 +26,15 @@ module LightService
26
26
 
27
27
  # More than one arguments can be passed to the
28
28
  # Organizer's #call method
29
+ # rubocop:disable Style/ArgumentsForwarding
29
30
  def with(*args, &block)
30
31
  catch(:return_ctx_from_execution) do
31
32
  @organizer.call(*args, &block)
32
33
  end
33
34
  end
35
+ # rubocop:enable Style/ArgumentsForwarding
36
+
37
+ ruby2_keywords :with if RUBY_VERSION >= "2.7"
34
38
 
35
39
  def initialize(organizer)
36
40
  @organizer = organizer
@@ -1,3 +1,3 @@
1
1
  module LightService
2
- VERSION = "0.17.0".freeze
2
+ VERSION = "0.19.0".freeze
3
3
  end
data/lib/light-service.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require 'logger'
2
- require 'active_support/core_ext/string'
3
2
 
4
3
  require 'light-service/version'
5
4
 
6
5
  require 'light-service/errors'
7
6
  require 'light-service/configuration'
8
- require 'light-service/localization_adapter'
9
7
  require 'light-service/context'
10
8
  require 'light-service/context/key_verifier'
9
+ require 'light-service/deprecation_warning'
10
+ require 'light-service/i18n/localization_adapter'
11
+ require 'light-service/localization_adapter'
12
+ require 'light-service/localization_map'
11
13
  require 'light-service/organizer/scoped_reducable'
12
14
  require 'light-service/organizer/with_reducer'
13
15
  require 'light-service/organizer/with_reducer_log_decorator'
@@ -15,6 +17,7 @@ require 'light-service/organizer/with_reducer_factory'
15
17
  require 'light-service/organizer/reduce_if'
16
18
  require 'light-service/organizer/reduce_if_else'
17
19
  require 'light-service/organizer/reduce_until'
20
+ require 'light-service/organizer/reduce_case'
18
21
  require 'light-service/organizer/iterate'
19
22
  require 'light-service/organizer/execute'
20
23
  require 'light-service/organizer/with_callback'
@@ -15,17 +15,14 @@ Gem::Specification.new do |gem|
15
15
  gem.name = "light-service"
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = LightService::VERSION
18
- gem.required_ruby_version = '>= 2.5.0'
19
-
20
- gem.add_runtime_dependency("activesupport", ">= 4.0.0")
18
+ gem.required_ruby_version = '>= 2.6.0'
21
19
 
22
20
  gem.add_development_dependency("generator_spec", "~> 0.9.4")
23
21
  gem.add_development_dependency("test-unit", "~> 3.0") # Needed for generator specs.
24
- gem.add_development_dependency("appraisal", "~> 2.3")
25
22
  gem.add_development_dependency("rspec", "~> 3.0")
26
23
  gem.add_development_dependency("simplecov", "~> 0.17")
27
24
  gem.add_development_dependency("codecov", "~> 0.1")
28
- gem.add_development_dependency("rubocop", "~> 0.68.0")
25
+ gem.add_development_dependency("rubocop", "~> 1.26.0")
29
26
  gem.add_development_dependency("rubocop-performance", "~> 1.2.0")
30
- gem.add_development_dependency("pry", "~> 0.12.2")
27
+ gem.add_development_dependency("pry", "~> 0.14")
31
28
  end
@@ -34,14 +34,10 @@ RSpec.describe 'Action after_actions' do
34
34
  class AdditionOrganizer
35
35
  extend LightService::Organizer
36
36
  after_actions (lambda do |ctx|
37
- if ctx.current_action == TestDoubles::AddsOneAction
38
- ctx.number -= 2
39
- end
37
+ ctx.number -= 2 if ctx.current_action == TestDoubles::AddsOneAction
40
38
  end),
41
39
  (lambda do |ctx|
42
- if ctx.current_action == TestDoubles::AddsThreeAction
43
- ctx.number -= 3
44
- end
40
+ ctx.number -= 3 if ctx.current_action == TestDoubles::AddsThreeAction
45
41
  end)
46
42
 
47
43
  def self.call(number)
@@ -69,9 +65,7 @@ RSpec.describe 'Action after_actions' do
69
65
  it 'ensures the correct :current_action is set' do
70
66
  TestDoubles::TestWithCallback.after_actions = [
71
67
  lambda do |ctx|
72
- if ctx.current_action == TestDoubles::IterateCollectionAction
73
- ctx.total -= 1000
74
- end
68
+ ctx.total -= 1000 if ctx.current_action == TestDoubles::IterateCollectionAction
75
69
  end
76
70
  ]
77
71
 
@@ -34,14 +34,10 @@ RSpec.describe 'Action before_actions' do
34
34
  class AdditionOrganizer
35
35
  extend LightService::Organizer
36
36
  before_actions (lambda do |ctx|
37
- if ctx.current_action == TestDoubles::AddsOneAction
38
- ctx.number -= 2
39
- end
37
+ ctx.number -= 2 if ctx.current_action == TestDoubles::AddsOneAction
40
38
  end),
41
39
  (lambda do |ctx|
42
- if ctx.current_action == TestDoubles::AddsThreeAction
43
- ctx.number -= 3
44
- end
40
+ ctx.number -= 3 if ctx.current_action == TestDoubles::AddsThreeAction
45
41
  end)
46
42
 
47
43
  def self.call(number)
@@ -69,9 +65,7 @@ RSpec.describe 'Action before_actions' do
69
65
  it 'can interact with actions from the outside' do
70
66
  TestDoubles::TestWithCallback.before_actions = [
71
67
  lambda do |ctx|
72
- if ctx.current_action == TestDoubles::AddToTotalAction
73
- ctx.total -= 1000
74
- end
68
+ ctx.total -= 1000 if ctx.current_action == TestDoubles::AddToTotalAction
75
69
  end
76
70
  ]
77
71
  result = TestDoubles::TestWithCallback.call
@@ -5,7 +5,7 @@ describe "Including is discouraged" do
5
5
  it "gives warning" do
6
6
  expected_msg = "including LightService::Organizer is deprecated. " \
7
7
  "Please use `extend LightService::Organizer` instead"
8
- expect(ActiveSupport::Deprecation).to receive(:warn)
8
+ expect(LightService::Deprecation).to receive(:warn)
9
9
  .with(expected_msg)
10
10
 
11
11
  class OrganizerIncludingLS
@@ -18,7 +18,7 @@ describe "Including is discouraged" do
18
18
  it "gives warning" do
19
19
  expected_msg = "including LightService::Action is deprecated. " \
20
20
  "Please use `extend LightService::Action` instead"
21
- expect(ActiveSupport::Deprecation).to receive(:warn)
21
+ expect(LightService::Deprecation).to receive(:warn)
22
22
  .with(expected_msg)
23
23
 
24
24
  class ActionIncludingLS
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
  require "test_doubles"
3
3
 
4
- class TestsLocalizationAdapter
4
+ class TestsI18nLocalizationAdapter
5
5
  extend LightService::Organizer
6
6
 
7
7
  def self.call(pass_or_fail, message_or_key, i18n_options = {})
@@ -9,11 +9,11 @@ class TestsLocalizationAdapter
9
9
  :pass_or_fail => pass_or_fail,
10
10
  :message_or_key => message_or_key,
11
11
  :i18n_options => i18n_options
12
- ).reduce(TestsLocalizationInvocationOptionsAction)
12
+ ).reduce(TestsI18nLocalizationInvocationOptionsAction)
13
13
  end
14
14
  end
15
15
 
16
- class TestsLocalizationInvocationOptionsAction
16
+ class TestsI18nLocalizationInvocationOptionsAction
17
17
  extend LightService::Action
18
18
  expects :pass_or_fail, :message_or_key, :i18n_options
19
19
 
@@ -27,18 +27,18 @@ class TestsLocalizationInvocationOptionsAction
27
27
  end
28
28
 
29
29
  def pass_with(message_or_key, i18n_options = {})
30
- TestsLocalizationAdapter.call(true, message_or_key, i18n_options)
30
+ TestsI18nLocalizationAdapter.call(true, message_or_key, i18n_options)
31
31
  end
32
32
 
33
33
  def fail_with(message_or_key, i18n_options = {})
34
- TestsLocalizationAdapter.call(false, message_or_key, i18n_options)
34
+ TestsI18nLocalizationAdapter.call(false, message_or_key, i18n_options)
35
35
  end
36
36
 
37
- describe "Localization Adapter" do
37
+ describe "I18n Localization Adapter" do
38
38
  before do
39
39
  I18n.backend.store_translations(
40
40
  :en,
41
- :tests_localization_invocation_options_action =>
41
+ :tests_i18n_localization_invocation_options_action =>
42
42
  {
43
43
  :light_service => {
44
44
  :failures => {
@@ -4,8 +4,8 @@ require 'test_doubles'
4
4
  describe "Organizer should invoke with/reduce from a call method" do
5
5
  context "when the organizer does not have a `call` method" do
6
6
  it "gives warning" do
7
- expect(ActiveSupport::Deprecation)
8
- .to receive(:warn)
7
+ expect(LightService)
8
+ .to receive(:deprecation_warning)
9
9
  .with(/^The <OrganizerWithoutCallMethod> class is an organizer/)
10
10
 
11
11
  class OrganizerWithoutCallMethod
@@ -22,7 +22,7 @@ describe "Organizer should invoke with/reduce from a call method" do
22
22
 
23
23
  context "when the organizer has the `call` method" do
24
24
  it "does not issue a warning" do
25
- expect(ActiveSupport::Deprecation)
25
+ expect(LightService::Deprecation)
26
26
  .not_to receive(:warn)
27
27
 
28
28
  class OrganizerWithCallMethod
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ RSpec.describe LightService::Organizer do
5
+ class TestReduceCase
6
+ extend LightService::Organizer
7
+
8
+ def self.call(context)
9
+ with(context).reduce(actions)
10
+ end
11
+
12
+ def self.actions
13
+ [
14
+ reduce_case(
15
+ :value => :incr_num,
16
+ :when => {
17
+ :one => [TestDoubles::AddsOneAction],
18
+ :two => [TestDoubles::AddsTwoAction],
19
+ :three => [TestDoubles::AddsThreeAction]
20
+ },
21
+ :else => [TestDoubles::FailureAction]
22
+ )
23
+ ]
24
+ end
25
+ end
26
+
27
+ it 'adds one if the incr_num is one' do
28
+ result = TestReduceCase.call(:number => 0, :incr_num => :one)
29
+
30
+ expect(result).to be_success
31
+ expect(result[:number]).to eq(1)
32
+ end
33
+
34
+ it 'adds two if the incr_num is two' do
35
+ result = TestReduceCase.call(:number => 0, :incr_num => :two)
36
+
37
+ expect(result).to be_success
38
+ expect(result[:number]).to eq(2)
39
+ end
40
+
41
+ it 'adds three if the incr_num is three' do
42
+ result = TestReduceCase.call(:number => 0, :incr_num => :three)
43
+
44
+ expect(result).to be_success
45
+ expect(result[:number]).to eq(3)
46
+ end
47
+
48
+ it 'will fail if the incr_num is neither one, two, or three' do
49
+ result = TestReduceCase.call(:number => 0, :incr_num => :four)
50
+
51
+ expect(result).to be_failure
52
+ end
53
+ end
@@ -63,6 +63,7 @@ RSpec.describe LightService::Organizer do
63
63
  reduce(actions)
64
64
  end
65
65
 
66
+ # rubocop:disable Metrics/AbcSize
66
67
  def self.actions
67
68
  [
68
69
  reduce_if(
@@ -76,6 +77,7 @@ RSpec.describe LightService::Organizer do
76
77
  execute(->(c) { c[:last_outside] = true })
77
78
  ]
78
79
  end
80
+ # rubocop:enable Metrics/AbcSize
79
81
  end
80
82
 
81
83
  result = org.call
@@ -12,7 +12,7 @@ RSpec.describe "skip_all! has been deprecated" do
12
12
 
13
13
  expected_msg = "Using skip_all! has been deprecated, " \
14
14
  "please use `skip_remaining!` instead."
15
- expect(ActiveSupport::Deprecation).to receive(:warn)
15
+ expect(LightService::Deprecation).to receive(:warn)
16
16
  .with(expected_msg)
17
17
 
18
18
  SkipAllDeprecatedAction.execute
@@ -13,13 +13,7 @@ RSpec.describe LightService::Context do
13
13
  describe '#inspect' do
14
14
  it 'inspects the hash with all the fields' do
15
15
  inspected_context =
16
- 'LightService::Context({}, ' \
17
- + 'success: true, ' \
18
- + 'message: \'\', ' \
19
- + 'error_code: nil, ' \
20
- + 'skip_remaining: false, ' \
21
- + 'aliases: {}' \
22
- + ')'
16
+ "LightService::Context({}, success: true, message: '', error_code: nil, skip_remaining: false, aliases: {})"
23
17
 
24
18
  expect(context.inspect).to eq(inspected_context)
25
19
  end
@@ -28,13 +22,8 @@ RSpec.describe LightService::Context do
28
22
  context.fail!('There was an error')
29
23
 
30
24
  inspected_context =
31
- 'LightService::Context({}, ' \
32
- + 'success: false, ' \
33
- + 'message: \'There was an error\', ' \
34
- + 'error_code: nil, ' \
35
- + 'skip_remaining: false, ' \
36
- + 'aliases: {}' \
37
- + ')'
25
+ "LightService::Context({}, success: false, message: 'There was an error', error_code: nil, " \
26
+ "skip_remaining: false, aliases: {})"
38
27
 
39
28
  expect(context.inspect).to eq(inspected_context)
40
29
  end
@@ -43,13 +32,8 @@ RSpec.describe LightService::Context do
43
32
  context.skip_remaining!('No need to process')
44
33
 
45
34
  inspected_context =
46
- 'LightService::Context({}, ' \
47
- + 'success: true, ' \
48
- + 'message: \'No need to process\', ' \
49
- + 'error_code: nil, ' \
50
- + 'skip_remaining: true, ' \
51
- + 'aliases: {}' \
52
- + ')'
35
+ "LightService::Context({}, success: true, message: 'No need to process', error_code: nil, " \
36
+ "skip_remaining: true, aliases: {})"
53
37
 
54
38
  expect(context.inspect).to eq(inspected_context)
55
39
  end
data/spec/context_spec.rb CHANGED
@@ -152,7 +152,7 @@ RSpec.describe LightService::Context do
152
152
  end
153
153
 
154
154
  it "warns about the outcome attribute reader being deprecated" do
155
- expect(ActiveSupport::Deprecation).to receive(:warn)
155
+ expect(LightService::Deprecation).to receive(:warn)
156
156
 
157
157
  expect(context.outcome).to eq(::LightService::Outcomes::SUCCESS)
158
158
  end
@@ -167,7 +167,7 @@ RSpec.describe LightService::Context do
167
167
  end
168
168
 
169
169
  it "allows a default block value for #fetch" do
170
- expect(context.fetch(:madeup) { :default }).to eq(:default)
170
+ expect(context.fetch(:madeup, :default)).to eq(:default)
171
171
  end
172
172
 
173
173
  context "when aliases are included via .make" do
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+ require 'test_doubles'
3
+
4
+ describe LightService::I18n::LocalizationAdapter do
5
+ let(:action_class) { TestDoubles::AnAction }
6
+ let(:adapter) { described_class.new }
7
+
8
+ describe "#failure" do
9
+ subject { adapter.failure(message_or_key, action_class) }
10
+
11
+ context "when provided a Symbol" do
12
+ let(:message_or_key) { :not_found }
13
+
14
+ it "translates the message" do
15
+ expected_scope = "test_doubles/an_action.light_service.failures"
16
+
17
+ expect(I18n).to receive(:t)
18
+ .with(message_or_key, :scope => expected_scope)
19
+ .and_return("message")
20
+
21
+ expect(subject).to eq("message")
22
+ end
23
+
24
+ it "allows passing interpolation options to I18n layer" do
25
+ expect(I18n).to receive(:t)
26
+ .with(message_or_key, hash_including(:i18n_variable => "value"))
27
+ .and_return("message")
28
+
29
+ subject = adapter.failure(message_or_key,
30
+ action_class,
31
+ :i18n_variable => "value")
32
+
33
+ expect(subject).to eq("message")
34
+ end
35
+ end
36
+
37
+ context "when provided a String" do
38
+ let(:message_or_key) { "action failed" }
39
+
40
+ it "returns the message" do
41
+ expect(subject).to eq(message_or_key)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#success" do
47
+ subject { adapter.success(message_or_key, action_class) }
48
+
49
+ context "when provided a Symbol" do
50
+ let(:message_or_key) { :not_found }
51
+
52
+ it "translates the message" do
53
+ expected_scope = "test_doubles/an_action.light_service.successes"
54
+
55
+ expect(I18n).to receive(:t)
56
+ .with(message_or_key, :scope => expected_scope)
57
+ .and_return("message")
58
+
59
+ expect(subject).to eq("message")
60
+ end
61
+
62
+ it "allows passing interpolation options to I18n layer" do
63
+ expect(I18n).to receive(:t)
64
+ .with(message_or_key, hash_including(:i18n_variable => "value"))
65
+ .and_return("message")
66
+
67
+ subject = adapter.success(message_or_key,
68
+ action_class,
69
+ :i18n_variable => "value")
70
+
71
+ expect(subject).to eq("message")
72
+ end
73
+ end
74
+
75
+ context "when provided a String" do
76
+ let(:message_or_key) { "action failed" }
77
+
78
+ it "returns the message" do
79
+ expect(subject).to eq(message_or_key)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/action_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/action_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::ActionGenerator, :type => :generator do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/action_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/action_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::ActionGenerator, :type => :generator do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/organizer_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/organizer_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::OrganizerGenerator, :type => :generator do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/organizer_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/organizer_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::OrganizerGenerator, :type => :generator do