Skip to content

Commit

Permalink
Pass selected workflow from AS controller to ASCreateService
Browse files Browse the repository at this point in the history
 * Allow AS controller to pass workflow_name param to service (thanks, @hortongn!)
 * Default ASCreateService to the default workflow if `nil` is passed
 * Add a test for the rake task

Fixes #3161
  • Loading branch information
mjgiarlo committed Apr 25, 2017
1 parent 8bb4514 commit 68facde
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/sufia/admin/admin_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def list_search_builder
end

def create_admin_set
AdminSetCreateService.new(@admin_set, current_user).create
AdminSetCreateService.new(@admin_set, current_user, params[:admin_set][:workflow_name]).create
end

def setup_form
Expand Down
2 changes: 1 addition & 1 deletion app/services/sufia/admin_set_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.create_default!
def initialize(admin_set, creating_user, workflow_name)
@admin_set = admin_set
@creating_user = creating_user
@workflow_name = workflow_name
@workflow_name = workflow_name || AdminSet::DEFAULT_WORKFLOW_NAME
end

attr_reader :creating_user, :admin_set, :workflow_name
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sufia/admin/admin_sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
let(:service) { instance_double(Sufia::AdminSetCreateService) }
before do
allow(Sufia::AdminSetCreateService).to receive(:new)
.with(AdminSet, user)
.with(AdminSet, user, 'default')
.and_return(service)
end

Expand Down
15 changes: 14 additions & 1 deletion spec/tasks/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
let!(:user2) { FactoryGirl.create(:user) }

before do
load_rake_environment [File.expand_path("../../../tasks/sufia_user.rake", __FILE__)]
load_rake_environment [
File.expand_path("../../../tasks/sufia_user.rake", __FILE__),
File.expand_path("../../../lib/tasks/default_admin_set.rake", __FILE__)
]
end

it "creates a file" do
Expand All @@ -23,5 +26,15 @@
expect(IO.read("abc123.txt")).to include(user1.email, user2.email)
File.delete("abc123.txt")
end

describe 'sufia:default_admin_set:create' do
before do
AdminSet.find(AdminSet::DEFAULT_ID).eradicate if AdminSet.exists?(AdminSet::DEFAULT_ID)
end

it 'creates the default AdminSet' do
expect { run_task 'sufia:default_admin_set:create' }.to change { AdminSet.count }.by(1)
end
end
end
end

0 comments on commit 68facde

Please sign in to comment.