Last active
August 29, 2015 14:03
-
-
Save camallen/154a733ffd72e94d69c9 to your computer and use it in GitHub Desktop.
mock cellect for functional tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe Api::V1::ClassificationsController, type: :controller do | |
| let!(:workflow) { create(:workflow_with_subjects) } | |
| let!(:set_member_subject) { workflow.subject_sets.first.set_member_subjects.first } | |
| let!(:user) { create(:user, cellect_hosts: { workflow.id.to_s => 'http://example.com' }) } | |
| let(:mocked_cellect) do | |
| cellect_connection = instance_double(Cellect::Client::Connection) | |
| expect(Cellect::Client).to receive(:connection).and_return(cellect_connection) | |
| cellect_connection | |
| end | |
| context "logged in user" do | |
| before(:each) do | |
| default_request user_id: user.id, scopes: ["classifications"] | |
| end | |
| describe "#create" do | |
| let(:params) do | |
| { workflow_id: workflow.id, subject_id: set_member_subject.id, annotations: [] } | |
| end | |
| def send_request | |
| post :create, params | |
| end | |
| it "should return 204" do | |
| allow(mocked_cellect).to receive(:add_seen) | |
| send_request | |
| expect(response.status).to eq(204) | |
| end | |
| it "should send the add seen command to cellect" do | |
| expect(mocked_cellect).to receive(:add_seen).with( | |
| set_member_subject.id.to_s, | |
| workflow_id: workflow.id.to_s, | |
| user_id: user.id, | |
| host: user.cellect_hosts[workflow.id.to_s] | |
| ) | |
| send_request | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment