Sha256: f5c601cfde7aa66f9821d8965690c12e90524d476152c74bc4080d75c10f25b6

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe HideAndSeek::ItemsController, :type => :controller do
  routes { HideAndSeek::Engine.routes }

  let(:current_user){double("User", :id => 1)}

  before do
    allow(controller).to receive(:current_user).and_return(current_user)
  end


  context "#show" do
    it "should check hide_and_seek with the id and the current user" do
      expect($hide_and_seek).to receive(:display?).with("foo", 1).and_return(true)
      get :show, id: "foo", format: :json
    end
    it "should render json display => true if successful" do
      allow($hide_and_seek).to receive(:display?).and_return true
      get :show, id: "foo", format: :json
      expect(response.body).to eq([display: true].to_json)
    end
    it "should render json display => false if unsuccessful" do
      allow($hide_and_seek).to receive(:display?).and_return false
      get :show, id: "foo", format: :json
      expect(response.body).to eq([display: false].to_json)
    end
    it "should params[:user_id] over current_user if sent" do
      expect($hide_and_seek).to receive(:display?).with("foo", 9001).and_return(true)
      get :show, id: "foo", format: :json, user_id: 9001
    end
  end

  context "#update" do
    it "should hide the item for the current_user" do
      expect($hide_and_seek).to receive(:hide).with("foo", 1)
      patch :update, id: "foo", format: :json
    end
    it "should render 200" do
      allow($hide_and_seek).to receive(:hide).and_return true
      patch :update, id: "foo", format: :json
      expect(response.status).to eq(200)
    end
    it "should respond with 502 if it can't be saved." do
      allow($hide_and_seek).to receive(:hide).and_return false
      patch :update, id: "foo", format: :json
      expect(response.status).to eq(502)
    end
    it "should params[:user_id] over current_user if sent" do
      expect($hide_and_seek).to receive(:hide).with("foo", 9001).and_return(true)
      patch :update, id: "foo", format: :json, user_id: 9001
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hide_and_seek-0.0.4 spec/hide_and_seek/controllers/items_controller_spec.rb
hide_and_seek-0.0.3 spec/hide_and_seek/controllers/items_controller_spec.rb
hide_and_seek-0.0.2 spec/hide_and_seek/controllers/items_controller_spec.rb
hide_and_seek-0.0.1 spec/hide_and_seek/controllers/items_controller_spec.rb