Sha256: ceec2694638145017121539dee336dc434792c79570236fa90998ab99f4bede1

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

require 'rails_helper'

RSpec.describe Wupee::Api::NotificationsController, type: :controller do
  routes { Wupee::Engine.routes }
  let(:notification) { create :notification }

  before :all do
    Wupee::Api::NotificationsController.class_eval do
      def current_user
      end
    end
  end

  before :each do
    allow_any_instance_of(Wupee::Api::NotificationsController).to receive(:current_user).and_return(notification.receiver)
  end

  it 'should get current user' do
    expect(subject).to receive(:current_user).and_return(notification.receiver)
    get :index, format: :json
  end

  describe 'GET index json' do
    render_views

    it "should returns a notification from a rendered template" do
      get :index, format: :json
      expect(json.size).to eq 1
      expect(json[0]['id']).to eq notification.id
      expect(json[0]['message']['subject']).to eq "subject"
    end
  end

  describe 'GET show json' do
    render_views

    it "should returns a notification from a rendered template" do
      get :show, format: :json, id: notification.id
      expect(json['id']).to eq notification.id
      expect(json['message']['subject']).to eq "subject"
    end
  end

  describe 'PUT update' do
    render_views

    it "should mark as read" do
      put :update, id: notification.id, format: :json
      expect(json['is_read']).to eq true
    end
  end

  describe 'PUT update_all' do
    render_views

    it "should all notification of user mark as read" do
      put :update_all, format: :json
      expect(notification.reload.is_read).to eq true
    end
  end

  def json
    ActiveSupport::JSON.decode(response.body)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wupee-1.1.4 spec/controllers/notifications_controller_spec.rb
wupee-1.1.3 spec/controllers/notifications_controller_spec.rb
wupee-1.1.2 spec/controllers/notifications_controller_spec.rb
wupee-1.0.4 spec/controllers/notifications_controller_spec.rb
wupee-1.0.3 spec/controllers/notifications_controller_spec.rb
wupee-1.0.2 spec/controllers/notifications_controller_spec.rb
wupee-1.0.1 spec/controllers/notifications_controller_spec.rb
wupee-1.0.0 spec/controllers/notifications_controller_spec.rb