Sha256: b8296c73fa4346ee12a39ea6881636711d8acb9c99f3bd2c7eded1669f8d866d

Contents?: true

Size: 1.79 KB

Versions: 5

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true
require "spec_helper"

module SocialNetworking
  describe ParticipantsController, type: :controller do
    let(:participant) do
      double("participant",
             id: 987,
             email: "foo@bar.com",
             latest_action_at: "2014-04-29T15:39:04.244-05:00",
             active_membership_end_date: nil)
    end

    before(:each) { @routes = Engine.routes }

    describe "GET index" do
      context "when the current participant is authenticated" do
        before do
          allow(controller).to receive(:authenticate_participant!)
          allow(Participant).to receive(:all) { [participant] }
        end

        it "should return the participants" do
          get :index

          assert_response 200
          expect(json.count).to eq(1)
          expect(json[0]["id"]).to eq(987)
        end
      end
    end

    describe "GET show" do
      context "when the current participant is authenticated" do
        before do
          allow(controller).to receive(:authenticate_participant!)
        end

        context "and the participant is found" do
          before do
            allow(Participant).to receive(:find).with("987") { participant }
          end

          it "should return the participant" do
            get :show, id: 987

            assert_response 200
            expect(json["id"]).to eq(987)
          end
        end

        context "and the participant is not found" do
          before do
            allow(Participant).to receive(:find)
              .and_raise(ActiveRecord::RecordNotFound)
          end

          it "should return the participant" do
            get :show, id: 987

            assert_response 404
            expect(json["error"]).to eq("participant not found")
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
social_networking-0.13.3 spec/controllers/social_networking/participants_controller_spec.rb
social_networking-0.13.2 spec/controllers/social_networking/participants_controller_spec.rb
social_networking-0.13.1 spec/controllers/social_networking/participants_controller_spec.rb
social_networking-0.13.0 spec/controllers/social_networking/participants_controller_spec.rb
social_networking-0.12.0 spec/controllers/social_networking/participants_controller_spec.rb