Sha256: 6b5e24e602d08efc83d04de400971bffd7aaea7410d3a5f4ef74e0b0965c84ff

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe BookmarksController do
  include Devise::TestHelpers
  
  # jquery 1.9 ajax does error callback if 200 returns empty body. so use 204 instead. 
  describe "update" do
    it "has a 204 status code when creating a new one" do
      xhr :put, :update, :id => '2007020969', :format => :js
      response.should be_success
      response.code.should == "204"
    end
    
    it "has a 500 status code when fails is success" do
      @controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
      @controller.stub_chain(:current_or_guest_user, :persisted?).and_return(true)
      @controller.stub_chain(:current_or_guest_user, :bookmarks, :create).and_return(false)  
      xhr :put, :update, :id => 'iamabooboo', :format => :js
      response.code.should == "500"
    end
  end
  
  describe "delete" do
    it "has a 204 status code when delete is success" do
      xhr :delete, :destroy, :id => '2007020969', :format => :js
      response.should be_success
      response.code.should == "204"
    end

   it "has a 500 status code when delete is not success" do
      bm = mock(Bookmark)
      @controller.stub_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
      @controller.stub_chain(:current_or_guest_user, :bookmarks, :delete).and_return(false)
     
      xhr :delete, :destroy, :id => 'pleasekillme', :format => :js
     #
      response.code.should == "500"
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blacklight-4.2.2 spec/controllers/bookmarks_controller_spec.rb
blacklight-4.2.1 spec/controllers/bookmarks_controller_spec.rb
blacklight-4.2.0 spec/controllers/bookmarks_controller_spec.rb