Merge pull request #5159 from opf/fix/24570/Replace-EE-token-does-not-report-errors-in-the-token

Fix/24570/Replace EE token does not report errors in the token
pull/5164/head
ulferts 8 years ago committed by GitHub
commit 40314668ab
  1. 10
      app/models/enterprise_token.rb
  2. 6
      app/views/enterprises/_form.html.erb
  3. 7
      spec/models/enterprise_token_spec.rb

@ -80,6 +80,13 @@ class EnterpriseToken < ActiveRecord::Base
RequestStore.delete :current_ee_token
end
def unset_current_token_object
# Clear current cache
if defined?(@token_object)
remove_instance_variable(:@token_object)
end
end
private
def load_token
@ -90,6 +97,7 @@ class EnterpriseToken < ActiveRecord::Base
end
def valid_token_object
errors.add(:encoded_token, :unreadable) unless token_object
unset_current_token_object
errors.add(:encoded_token, :unreadable) unless load_token
end
end

@ -6,7 +6,7 @@
<% end %>
<%= labelled_tabular_form_for @token,
url: { action: :create },
html: { class: 'token-form' },
html: { class: 'token-form form -vertical' },
method: :post do |f|%>
<div class="form--space">
@ -14,8 +14,8 @@
</div>
<div class="form--space">
<%= styled_button_tag t(:button_create), id: 'token-submit-button', class: '-highlight -with-icon icon-checkmark' %>
<%= styled_button_tag t(:button_save), id: 'token-submit-button', class: '-highlight -with-icon icon-checkmark' %>
<%= link_to t(:button_cancel), { action: :show }, class: 'button' %>
</div>
<% end %>
</collapsible-section>
</collapsible-section>

@ -77,6 +77,13 @@ RSpec.describe EnterpriseToken, type: :model do
expect(EnterpriseToken.show_banners).to eq(true)
end
end
context 'updating it with an invalid token' do
it 'will fail validations' do
subject.encoded_token = "bar"
expect(subject.save).to be_falsey
end
end
end
describe 'no token' do

Loading…
Cancel
Save