Sha256: 726441624d8445f7af475caa92d53bf3b75b5d8edf9e9a86a3fc8c351f3cda6f

Contents?: true

Size: 1.73 KB

Versions: 4

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

module Gamification
  describe Goal do
    let(:subject) { create :user }
    let(:goal) { create :gamification_goal }

    describe '#completed_by?' do
      context 'for a goal that is completed by the given subject' do
        before do
          create :gamification_reward, goal: goal, rewardable: subject
        end

        it 'returns true' do
          expect(goal).to be_completed_by subject
        end
      end

      context 'for a goal that is not completed by the given subject' do
        it 'returns false' do
          expect(goal).not_to be_completed_by subject
        end
      end
    end

    describe '#complete_for' do
      context 'for a goal that is not yet completed' do
        it 'creates a reward for the given subject' do
          expect(goal.complete_for subject).to be_instance_of Reward
        end
      end

      context 'for a goal that is already completed' do
        before do
          create :gamification_reward, goal: goal, rewardable: subject
        end

        it 'raises an error' do
          expect { goal.complete_for subject}.to raise_error Goal::Completed
        end
      end
    end

    describe '.completed_by' do
      let!(:complete_goal)   { create :gamification_goal }
      let!(:incomplete_goal) { create :gamification_goal }

      before do
        complete_goal.complete_for subject
      end

      it 'returns completed goals by a given subject' do
        expect(Goal.completed_by(subject).count).to eq 1
      end
    end

    describe '.incomplete_by' do
      let!(:incomplete_goals) { create_list :gamification_goal, 2 }

      it 'returns incomplete goals by a given subject' do
        expect(Goal.incomplete_by(subject).count).to eq 2
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gamification-1.0.3 spec/models/gamification/goal_spec.rb
gamification-1.0.2 spec/models/gamification/goal_spec.rb
gamification-1.0.1 spec/models/gamification/goal_spec.rb
gamification-1.0.0 spec/models/gamification/goal_spec.rb