Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor DependencyError #3344

Merged
merged 1 commit into from
Aug 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/active_admin/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module Dependency
# => true
#
# ActiveAdmin::Dependency.rails! '2'
# -> ActiveAdmin::Dependency::Error: You provided rails 3.2.18 but we need: 2.
# -> ActiveAdmin::DependencyError: You provided rails 3.2.18 but we need: 2.
#
# ActiveAdmin::Dependency.devise!
# -> ActiveAdmin::Dependency::Error: To use devise you need to specify it in your Gemfile.
# -> ActiveAdmin::DependencyError: To use devise you need to specify it in your Gemfile.
#
#
# All but the pessimistic operator (~>) can also be run using Ruby's comparison syntax.
Expand Down Expand Up @@ -64,11 +64,11 @@ def match?(*reqs)

def match!(*reqs)
unless @spec
raise Error, "To use #{@name} you need to specify it in your Gemfile."
raise DependencyError, "To use #{@name} you need to specify it in your Gemfile."
end

unless match? reqs
raise Error, "You provided #{@spec.name} #{@spec.version} but we need: #{reqs.join ', '}."
raise DependencyError, "You provided #{@spec.name} #{@spec.version} but we need: #{reqs.join ', '}."
end
end

Expand All @@ -80,7 +80,7 @@ def <=>(other)
else
# you'd otherwise get an unhelpful error message:
# ArgumentError: comparison of ActiveAdmin::Dependency::Matcher with 2 failed
raise Error, "To use #{@name} you need to specify it in your Gemfile."
raise DependencyError, "To use #{@name} you need to specify it in your Gemfile."
end
end

Expand All @@ -89,8 +89,5 @@ def inspect
"<ActiveAdmin::Dependency::Matcher for #{info}>"
end
end

class Error < ::ActiveAdmin::ErrorLoading; end

end
end
4 changes: 4 additions & 0 deletions lib/active_admin/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def self.database_error_classes
end
end

class DependencyError < ErrorLoading
end

class NoMenuError < KeyError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an end

end

end
2 changes: 1 addition & 1 deletion lib/generators/active_admin/devise/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeviseGenerator < Rails::Generators::NamedBase
def install_devise
begin
Dependency.devise! Dependency::DEVISE
rescue Dependency::Error => e
rescue DependencyError => e
raise Error, "#{e.message} If you don't want to use devise, run the generator with --skip-users."
end

Expand Down
12 changes: 6 additions & 6 deletions spec/unit/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@

describe '`!`' do
it 'raises an error if requirement not met' do
expect{ k.foo! '5' }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k.foo! '5' }.to raise_error ActiveAdmin::DependencyError,
'You provided foo 1.2.3 but we need: 5.'
end
it 'accepts multiple arguments' do
expect{ k.foo! '> 1', '< 1.2' }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k.foo! '> 1', '< 1.2' }.to raise_error ActiveAdmin::DependencyError,
'You provided foo 1.2.3 but we need: > 1, < 1.2.'
end
it 'raises an error if not provided' do
expect{ k.bar! }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k.bar! }.to raise_error ActiveAdmin::DependencyError,
'To use bar you need to specify it in your Gemfile.'
end
end
Expand Down Expand Up @@ -90,10 +90,10 @@
expect(k['a-b'].match! ).to eq nil
expect(k['a-b'].match! '1.2.3').to eq nil

expect{ k['a-b'].match! '2.5' }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k['a-b'].match! '2.5' }.to raise_error ActiveAdmin::DependencyError,
'You provided a-b 1.2.3 but we need: 2.5.'

expect{ k['b-c'].match! }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k['b-c'].match! }.to raise_error ActiveAdmin::DependencyError,
'To use b-c you need to specify it in your Gemfile.'
end

Expand Down Expand Up @@ -126,7 +126,7 @@
end

it 'throws a custom error if the gem is missing' do
expect{ k['b-c'] < 23 }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k['b-c'] < 23 }.to raise_error ActiveAdmin::DependencyError,
'To use b-c you need to specify it in your Gemfile.'
end
end
Expand Down