Permalink
Browse files

Merge bug fix from branch 'artefact-audit-trail'.

  • Loading branch information...
2 parents e1ec482 + 6465ac2 commit 43ac18e507fe8c19da108bce84186a4158af3b08 @fatbusinessman fatbusinessman committed Aug 7, 2012
Showing with 33 additions and 3 deletions.
  1. +9 −2 app/controllers/artefacts_controller.rb
  2. +19 −0 test/functional/artefacts_controller_test.rb
  3. +5 −1 test/test_helper.rb
View
11 app/controllers/artefacts_controller.rb
@@ -37,7 +37,7 @@ def edit
end
def create
- @artefact.save_as current_user
+ @artefact.save_as action_user
respond_with @artefact, location: @artefact.admin_url(params.slice(:return_to))
end
@@ -62,7 +62,7 @@ def update
return
end
- saved = @artefact.update_attributes_as(current_user, parameters_to_use)
+ saved = @artefact.update_attributes_as(action_user, parameters_to_use)
flash[:notice] = saved ? 'Panopticon item updated' : 'Failed to save item'
if saved && params[:commit] == 'Save and continue editing'
@@ -111,4 +111,11 @@ def extract_parameters(params)
parameters_to_use
end
+ def action_user
+ # The user to associate with actions
+ # Currently this returns nil for the API user: this should go away once
+ # we have real user authentication for API requests
+ action_user = current_user.is_a?(User) ? current_user : nil
+ end
+
end
View
19 test/functional/artefacts_controller_test.rb
@@ -158,6 +158,25 @@ class ArtefactsControllerTest < ActionController::TestCase
assert_equal stub_user, artefact.actions.last.user
end
+ should "Not record the user for API requests" do
+ login_as GDS::SSO::ApiUser.new
+ artefact = Artefact.create!(
+ :slug => 'whatever',
+ :kind => 'guide',
+ :owning_app => 'publisher',
+ :rendering_app => 'frontend',
+ :name => 'Whatever',
+ :need_id => 1
+ )
+
+ put :update, id: artefact.id, format: :json, name: "Changed"
+ assert_response :success
+
+ artefact.reload
+ assert_equal nil, artefact.actions.last.user
+ end
+
+
should "Update our primary section and ensure it persists into sections" do
@tags = FactoryGirl.create_list(:tag, 3)
artefact = Artefact.create!(:slug => 'whatever', :kind => 'guide',
View
6 test/test_helper.rb
@@ -41,10 +41,14 @@ def stub_user
end
def login_as_stub_user
+ login_as stub_user
+ end
+
+ def login_as(user)
request.env['warden'] = stub(
:authenticate! => true,
:authenticated? => true,
- :user => stub_user
+ :user => user
)
end

0 comments on commit 43ac18e

Please sign in to comment.