Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit 57bc70e

Browse files
committed
Merge pull request #228 from joeadcock/master
Sets default configuration without a config file
2 parents 35b39de + f1002b3 commit 57bc70e

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

lib/griddler/configuration.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@ def self.configuration
1616
end
1717

1818
class Configuration
19-
attr_accessor :processor_class, :processor_method, :reply_delimiter
19+
attr_accessor :processor_method
2020

2121
def processor_class
2222
@processor_class ||=
2323
begin
24-
if Kernel.const_defined?(:EmailProcessor)
25-
"EmailProcessor"
26-
else
27-
raise NameError.new(<<-ERROR.strip_heredoc, 'EmailProcessor')
28-
To use Griddler, you must either define `EmailProcessor` or configure a
29-
different processor. See https://github.com/thoughtbot/griddler#defaults for
30-
more information.
31-
ERROR
32-
end
24+
EmailProcessor.to_s
25+
rescue NameError
26+
raise NameError.new(<<-ERROR.strip_heredoc, 'EmailProcessor')
27+
To use Griddler, you must either define `EmailProcessor` or configure a
28+
different processor. See https://github.com/thoughtbot/griddler#defaults for
29+
more information.
30+
ERROR
3331
end
34-
3532
@processor_class.constantize
3633
end
37-
34+
3835
def processor_class=(klass)
3936
@processor_class = klass.to_s
4037
end
@@ -48,7 +45,9 @@ def reply_delimiter
4845
end
4946

5047
def email_service
51-
@email_service_adapter ||= Griddler.adapter_registry[:default]
48+
@email_service_adapter ||=
49+
Griddler.adapter_registry[:default] ||
50+
raise(Griddler::Errors::EmailServiceAdapterNotFound)
5251
end
5352

5453
def email_service=(new_email_service)

spec/griddler/configuration_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@
1414
end
1515

1616
it 'raises a helpful error if EmailProcessor is undefined' do
17-
allow(Kernel).to receive_messages(const_defined?: false)
17+
# temporarily undefine EmailProcessor
18+
ep = EmailProcessor
19+
Object.send(:remove_const, :EmailProcessor)
20+
allow(ActiveSupport::Dependencies).to(
21+
receive_messages(search_for_file: nil))
1822

19-
expect { Griddler.configuration.processor_class }.to raise_error(NameError, %r{https://github\.com/thoughtbot/griddler#defaults})
23+
expect { Griddler.configuration.processor_class }.to raise_error(
24+
NameError, %r{https://github\.com/thoughtbot/griddler#defaults})
25+
26+
# restore EmailProcessor
27+
EmailProcessor = ep
2028
end
2129
end
2230

0 commit comments

Comments
 (0)