From 1352d9f31e108a706492295545f6c44063075930 Mon Sep 17 00:00:00 2001 From: Wieland Lindenthal Date: Thu, 19 Jan 2017 11:42:53 +0100 Subject: [PATCH 1/2] The validation of a token needs to load the token_object every time. --- app/models/enterprise_token.rb | 10 +++++++++- spec/models/enterprise_token_spec.rb | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb index dba41ce8b4..4083054e26 100644 --- a/app/models/enterprise_token.rb +++ b/app/models/enterprise_token.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 diff --git a/spec/models/enterprise_token_spec.rb b/spec/models/enterprise_token_spec.rb index 3836ed9738..50b92d1ba9 100644 --- a/spec/models/enterprise_token_spec.rb +++ b/spec/models/enterprise_token_spec.rb @@ -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 From 40b214f21359753222627c7fb518815f9e028642 Mon Sep 17 00:00:00 2001 From: Wieland Lindenthal Date: Thu, 19 Jan 2017 11:43:42 +0100 Subject: [PATCH 2/2] Change caption for saving a taken to "save"; fix markup for vertical form. --- app/views/enterprises/_form.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/enterprises/_form.html.erb b/app/views/enterprises/_form.html.erb index 9c7f2637f0..eceed633e1 100644 --- a/app/views/enterprises/_form.html.erb +++ b/app/views/enterprises/_form.html.erb @@ -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|%>
@@ -14,8 +14,8 @@
- <%= 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' %>
<% end %> - \ No newline at end of file +