Skip to content

Commit

Permalink
Fix Hound style checks
Browse files Browse the repository at this point in the history
  • Loading branch information
talklittle committed Jan 3, 2018
1 parent 23bc48f commit a1592d0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
12 changes: 7 additions & 5 deletions lib/doorkeeper/models/application_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ module ApplicationMixin
validates :uid, uniqueness: true
validates :redirect_uri, redirect_uri: true

validates_each :scopes, if: :validate_configured_scopes? do |record, attr, value|
value_str = value.to_s
record.errors.add attr, :invalid_scope unless value_str.blank? or
ScopeChecker.valid?(value_str, Doorkeeper.configuration.scopes)
validates_each :scopes, if: :enforce_scopes? do |record, attr, value|
valstr = value.to_s
unless valstr.blank? ||
ScopeChecker.valid?(valstr, Doorkeeper.configuration.scopes) do
record.errors.add attr, :invalid_scope
end
end

before_validation :generate_uid, :generate_secret, on: :create
Expand Down Expand Up @@ -56,7 +58,7 @@ def has_scopes?
Doorkeeper::Application.column_names.include?("scopes")
end

def validate_configured_scopes?
def enforce_scopes?
Doorkeeper.configuration.enforce_configured_scopes?
end

Expand Down
52 changes: 26 additions & 26 deletions spec/requests/applications/applications_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,42 @@
i_should_see 'Whoops! Check your form for possible errors'
end

scenario 'adding app ignoring bad scope' do
config_is_set('enforce_configured_scopes', false)
scenario "adding app ignoring bad scope" do
config_is_set("enforce_configured_scopes", false)

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: 'blahblah'
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: "blahblah"

click_button 'Submit'
i_should_see 'Application created'
i_should_see 'My Application'
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end

scenario 'adding app validating bad scope' do
config_is_set('enforce_configured_scopes', true)
scenario "adding app validating bad scope" do
config_is_set("enforce_configured_scopes", true)

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: 'blahblah'
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: "blahblah"

click_button 'Submit'
i_should_see 'Whoops! Check your form for possible errors'
click_button "Submit"
i_should_see "Whoops! Check your form for possible errors"
end

scenario 'adding app validating scope, blank scope is accepted' do
config_is_set('enforce_configured_scopes', true)
scenario "adding app validating scope, blank scope is accepted" do
config_is_set("enforce_configured_scopes", true)

fill_in 'doorkeeper_application[name]', with: 'My Application'
fill_in 'doorkeeper_application[redirect_uri]',
with: 'https://example.com'
fill_in 'doorkeeper_application[scopes]', with: ''
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: ""

click_button 'Submit'
i_should_see 'Application created'
i_should_see 'My Application'
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end
end
end
Expand Down

0 comments on commit a1592d0

Please sign in to comment.