aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-09-14 23:57:15 +0200
committerRobert2017-09-14 23:57:15 +0200
commit402ba92a128e697fe6da754ee3454c315afebacb (patch)
treeeb1ed05a4679761257ebf7c791edb36698f9a089
parent9c9667baba6cc265b4756eb40ac35cdac3b7439d (diff)
downloadchouette-core-402ba92a128e697fe6da754ee3454c315afebacb.tar.bz2
Refs: #4446@1h; Api Keys Edit feature speced
-rw-r--r--app/policies/api_key_policy.rb3
-rw-r--r--spec/features/api_keys/edit_api_key_feature_spec.rb39
-rw-r--r--spec/features/api_keys/new_api_key_feature_spec.rb (renamed from spec/features/api_keys/api_keys_new_feature_spec.rb)0
3 files changed, 41 insertions, 1 deletions
diff --git a/app/policies/api_key_policy.rb b/app/policies/api_key_policy.rb
index bc5c9e433..eb7b84457 100644
--- a/app/policies/api_key_policy.rb
+++ b/app/policies/api_key_policy.rb
@@ -14,6 +14,7 @@ class ApiKeyPolicy < ApplicationPolicy
end
def update?
- organisation_match? && user.has_permission?('api_keys.update')
+ record.try(:organisation_id) == user.organisation_id &&
+ user.has_permission?('api_keys.update')
end
end
diff --git a/spec/features/api_keys/edit_api_key_feature_spec.rb b/spec/features/api_keys/edit_api_key_feature_spec.rb
new file mode 100644
index 000000000..411c11aaf
--- /dev/null
+++ b/spec/features/api_keys/edit_api_key_feature_spec.rb
@@ -0,0 +1,39 @@
+RSpec.describe 'New API Key', type: :feature do
+ login_user
+
+ describe "api_keys#edit" do
+
+ let!( :api_key ){ create :api_key, name: SecureRandom.uuid, organisation: @user.organisation }
+
+ let( :edit_label ){ "#{api_key.name} : #{api_key.token}" }
+ let( :name_label ){ "Nom" }
+ let( :validate_label ){ "Valider" }
+
+ let( :unique_name ){ SecureRandom.uuid }
+
+ it 'complete workflow' do
+ # /workbenches
+ visit workbenches_path
+ # api_key's new name does not exist yet
+ expect( page ).not_to have_content(unique_name)
+ # the api_key is visible
+ click_link edit_label
+
+ # brings us to correct page
+ expect(page.current_path).to eq(edit_api_key_path(api_key))
+ fill_in(name_label, with: unique_name)
+ click_button(validate_label)
+
+ # check impact on DB
+ expect(api_key.reload.name).to eq(unique_name)
+
+ # check redirect and changed display
+ expect(page.current_path).to eq(workbenches_path)
+ # changed api_key's name exists now
+ expect( page ).to have_content(unique_name)
+ end
+
+ end
+
+end
+
diff --git a/spec/features/api_keys/api_keys_new_feature_spec.rb b/spec/features/api_keys/new_api_key_feature_spec.rb
index eba873691..eba873691 100644
--- a/spec/features/api_keys/api_keys_new_feature_spec.rb
+++ b/spec/features/api_keys/new_api_key_feature_spec.rb