<commit_before>require 'spec_helper'

module ChooChoo
  describe Activity do
    pending "add some examples to (or delete) #{__FILE__}"
  end
end<commit_msg>Tested C(R)UD operations for parents and children<commit_after>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
{'fraction_non_alphanumeric': 0.08544795442775764, 'fraction_numerical': 0.0005178663904712584, 'mean_word_length': 2.5063520871143377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2218682', 'n_tokens_mistral': 548, 'n_tokens_neox': 534, 'n_words': 171}