spec/lib/shamu/rails/entity_spec.rb in shamu-0.0.9 vs spec/lib/shamu/rails/entity_spec.rb in shamu-0.0.11

- old
+ new

@@ -13,12 +13,10 @@ Shamu::Entities::List.new [ find( 1 ) ] end def authorize!( * ) end - - end class ExampleEntity < Shamu::Entities::Entity attribute :id end @@ -32,24 +30,28 @@ describe Shamu::Rails::Entity, type: :controller do hunt( :example_service, LoadEntitySpec::Service ) { scorpion.new LoadEntitySpec::Service } controller ActionController::Base do - service :example_service, LoadEntitySpec::Service + service :examples_service, LoadEntitySpec::Service entity LoadEntitySpec::ExampleEntity def show - render text: "" + render plain: "" end def index - render text: "" + render plain: "" end def new + render plan: "" + end + + def create example_request - render text: "" + render plain: "" end end before( :each ) do @@ -60,10 +62,11 @@ expect( controller.respond_to?( :example, true ) ).to be_truthy end it "loads the entity from the service" do expect( example_service ).to receive( :find ) + controller.params[:id] = 1 controller.send :example end it "adds an #example_request method" do expect( controller.respond_to?( :example_request, true ) ).to be_truthy @@ -81,70 +84,85 @@ controller.send :example_request end it "loads the entity before the request" do expect( controller ).to receive( :example ).and_call_original - get :show, id: 1 + get :show, params: { id: 1 } end it "invokes list for index types" do expect( controller ).to receive( :examples ).and_call_original get :index end it "authorizes action for entity request" do expect( example_service ).to receive( :authorize! ) - get :new + post :create end + it "doesn't load entity on create actions" do + expect( controller ).not_to receive( :example ) + + post :create + end + context "only some actions" do controller ActionController::Base do service :example_service, LoadEntitySpec::Service entity LoadEntitySpec::ExampleEntity, only: :show def show - render text: "" + render plain: "" end def new - render text: "" + render plain: "" end + + def create + render plain: "" + end end it "loads on show" do expect( controller ).to receive( :example ) - get :show, id: 1 + get :show, params: { id: 1 } end it "doesn't load on new" do expect( controller ).not_to receive( :example ) + post :create get :new end end context "except some actions" do controller ActionController::Base do service :example_service, LoadEntitySpec::Service entity LoadEntitySpec::ExampleEntity, except: :show def show - render text: "" + render plain: "" end def new - render text: "" + render plain: "" end + + def create + render plain: "" + end end it "loads on show" do expect( controller ).not_to receive( :example ) - get :show, id: 1 + get :show, params: { id: 1 } end it "doesn't load on new" do - expect( controller ).to receive( :example ) + expect( controller ).not_to receive( :example ) get :new end end -end \ No newline at end of file +end