Sha256: 59890be869fc921cdcb038dc4e2072acafe1085dd7b2321e99684fdbb73e75d7

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

module ChooChoo
  describe Activity do

    describe "parent events" do
      it "is created when a parent is created" do
        expect {
          create(:post)
        }.to change {Activity.count}.by(1)
      end

      it "is updated when a parent is updated" do
        post = create(:post)
        comment = create(:comment, post: post)
        post.update_attributes(title: 'Changed title')

        expect(post.activity.last_action).to eq 'updated'
        expect(post.activity.last_updated_node).to eq post
      end

      it "is left when a parent is deleted" do
        post = create(:post)
        activity = post.activity
        post.destroy

        expect(activity.last_action).to eq 'destroyed'
        expect(activity.last_updated_node).to be_nil
      end
    end

    describe "child events" do
      it "is updated when a child is created" do
        post = create(:post)
        comment = create(:comment, post: post)

        expect(post.activity.last_action).to eq 'created'
        expect(post.activity.last_updated_node).to eq comment
      end


      it "is updated when a child is updated" do
        post = create(:post)
        comment = create(:comment, post: post)
        comment.update_attributes(body: 'Changed comment')

        expect(post.activity.last_action).to eq 'updated'
        expect(post.activity.last_updated_node).to eq comment
      end

      it "is updated when a child is deleted" do
        post = create(:post)
        comment = create(:comment, post: post)
        comment.destroy

        expect(post.activity.last_action).to eq 'deleted'
        expect(post.activity.last_updated_node).to eq comment
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
choo_choo-0.0.1 spec/models/choo_choo/activity_spec.rb