Skip to content

Commit

Permalink
basic tests for BookmarksController refworks and endnote export
Browse files Browse the repository at this point in the history
  • Loading branch information
jrochkind committed Mar 25, 2014
1 parent 9758a90 commit f356868
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions spec/controllers/bookmarks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,67 @@

describe BookmarksController do
include Devise::TestHelpers

describe "index" do
render_views

before(:all) do
# creating a user without persisting it seems to work
@user_with_3 = User.new
# 3 ids from the sample data set
@user_with_3.bookmarks.new(:document_id => '43037890')
@user_with_3.bookmarks.new(:document_id => '53029833')
@user_with_3.bookmarks.new(:document_id => '77826928')

end

context ".endnote format" do
it "returns records in endnote format" do
@controller.stub(:current_or_guest_user).and_return(@user_with_3)

get :index, :format => :endnote

expect(response.code).to eq "200"

# For some reason having trouble getting actual doc.export_as(:endnote)
# to compare it, so we just make sure it seems mostly endnote-like, 3
# records seperated by blank lines.
expect(response.body).to match /\A(%. .*\n)+\n(%. .*\n)+\n(%. .*\n)+\Z/
end
end
end

describe "export" do
render_views

before(:all) do
# We don't persist the user, but we're gonna have to mock
# User.find to find it.
@user_with_3 = User.new
# 3 ids from the sample data set
@user_with_3.bookmarks.new(:document_id => '43037890')
@user_with_3.bookmarks.new(:document_id => '53029833')
@user_with_3.bookmarks.new(:document_id => '77826928')
end

context ".refworks_marc_txt format" do
it "returns records in refworks_marc_txt format from encrypted_user_id" do
user_id = 9999999999
encrypted_user_id = @controller.send(:encrypt_user_id, user_id)

User.should_receive(:find).with(user_id).and_return(@user_with_3)

get :export, :format => :refworks_marc_txt, :encrypted_user_id => encrypted_user_id

expect(response.code).to eq "200"
# For some reason having trouble getting actual doc.export_as(:refworks_marc_txt)
# to compare it, so we just make sure it seems to match the format for 3
# such records seperated by blank lines.
rmt_regex = 'LEADER .+\n(\d\d\d .. .+\n)+'
expect(response.body).to match /\A#{rmt_regex}\n#{rmt_regex}\n#{rmt_regex}\Z/
end
end
end

# jquery 1.9 ajax does error callback if 200 returns empty body. so use 204 instead.
describe "update" do
Expand Down

0 comments on commit f356868

Please sign in to comment.