Sha256: f430fffb5296c1a98bb39b424be0d6f9ec50b054afccaaffda0645e2d8410975

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Neutral::Voting do
  it { should belong_to(:votingable) }
  
  let(:voting) { Neutral::Voting.create }
  let(:nature) { [:positive, :negative].sample }

  describe "#difference" do
    let(:positive) { rand(100) }
    let(:negative) { rand(100) }

    subject { Neutral::Voting.new(positive: positive, negative: negative).difference }
    it { should == positive - negative }
  end

  describe "#self.init" do
    let(:vote) { FactoryGirl.build(:vote) }

    subject { Neutral::Voting.init(vote) }

    it { should be_a(Neutral::Voting) }
    it { should be_persisted }
    its(:votingable_type) { should == vote.voteable_type } 
    its(:votingable_id) { should == vote.voteable_id }
    it { subject.send(vote.nature).should == 1 }
  end

  describe "#add_to_existing" do
    it "adds vote to an existing voting" do
      voting.should_receive(:increment!).with(nature)
      voting.add_to_existing(nature)
    end
  end

  describe "#edit" do
    it "edits vote withing voting" do
      voting.should_receive(:increment).with(nature)
      voting.should_receive(:decrement).with(nature==:positive ? :negative : :positive)
      voting.should_receive(:save)
      voting.edit(nature)
    end
  end

  describe "#remove" do
    it "removes vote from voting" do
      voting.should_receive(:decrement!).with(nature)
      voting.remove(nature)
    end
  end

  describe "before_destroy" do
    let(:voting) { FactoryGirl.create(:vote).voting }

    it "deletes voting's votes" do
      voting.votes.should_receive(:delete_all)
      voting.destroy
    end
  end 
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
neutral-0.0.7 spec/models/voting_spec.rb
neutral-0.0.6 spec/models/voting_spec.rb
neutral-0.0.5 spec/models/voting_spec.rb
neutral-0.0.4 spec/models/voting_spec.rb
neutral-0.0.3 spec/models/voting_spec.rb
neutral-0.0.2 spec/models/voting_spec.rb
neutral-0.0.1 spec/models/voting_spec.rb