Skip to content

Commit

Permalink
Move signup lookup into it's own Interactor
Browse files Browse the repository at this point in the history
Trying to stay away from direct Repository access in the controller but
for now making this a static method instead of a full object as it's so simple.
  • Loading branch information
jasonroelofs committed Jul 13, 2012
1 parent cf14657 commit 92c4fb5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/signups_controller.rb
Expand Up @@ -18,7 +18,7 @@ def create
#
# Run +command+ on the given signup
def update
signup = Repository.for(Signup).find params[:id].to_i
signup = FindSignup.by_id(params[:id].to_i)
action = UpdateSignup.new current_user, signup
action.run params[:command]

Expand Down
8 changes: 8 additions & 0 deletions app/interactors/find_signup.rb
@@ -0,0 +1,8 @@
require 'repository'
require 'models/signup'

class FindSignup
def self.by_id(id)
Repository.for(Signup).find(id)
end
end
2 changes: 1 addition & 1 deletion test/integration/signups_controller_test.rb
Expand Up @@ -41,7 +41,7 @@ class SignupsControllerTest < ActionController::TestCase
raid = Raid.new id: 7
signup = Signup.new raid: raid

Repository.for(Signup).expects(:find).with(14).returns(signup)
FindSignup.expects(:by_id).with(14).returns(signup)
UpdateSignup.any_instance.expects(:run).with("accept")

put :update, :id => 14, :command => :accept
Expand Down
16 changes: 16 additions & 0 deletions test/unit/interactors/find_signup.rb
@@ -0,0 +1,16 @@
require 'unit/test_helper'
require 'models/signup'
require 'interactors/find_signup'

describe FindSignup do

describe ".by_id" do
it "returns the signup with the given id" do
s = Signup.new id: 4
Repository.for(Signup).save(s)

FindSignup.by_id(4).must_equal s
end
end

end

0 comments on commit 92c4fb5

Please sign in to comment.