Sha256: 05fc7ca96b835882d8542eb2748c40750b2cfa668833b694ea0f19934b67d3c1

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

module Gamification
  describe RewardsController do
    routes { Gamification::Engine.routes }

    describe "POST 'create'" do
      context 'all goals for a given rewardable' do
        let(:article) { create :article }
        let(:subject) { create :user }

        before do
          create :gamification_goal, rewarding: article
        end

        before do
          post 'create', redirect_url: 'http://example.org', reward: {
            rewarding_type: article.class.name,
            rewarding_id: article.id,
            rewardable_type: subject.class.name,
            rewardable_id: subject.id
          }
        end

        it 'should create a reward' do
          expect(Reward.count).to eq 1
        end

        it 'should redirect' do
          expect(response).to be_redirect
        end
      end

      context 'a single goal' do
        let(:goal)    { create :gamification_goal }
        let(:subject) { create :user }

        before do
          post 'create', redirect_url: 'http://example.org', reward: {
            rewarding_type: goal.class.name,
            rewarding_id: goal.id,
            rewardable_type: subject.class.name,
            rewardable_id: subject.id
          }
        end

        it 'should create a reward' do
          expect(Reward.count).to eq 1
        end

        it 'should redirect' do
          expect(response).to be_redirect
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gamification-1.0.0 spec/controllers/gamification/rewards_controller_spec.rb