spec/parole/comment_spec.rb in parole-0.1.2 vs spec/parole/comment_spec.rb in parole-0.1.3

- old
+ new

@@ -1,8 +1,46 @@ require 'spec_helper' describe Parole::Comment do + describe :Validations do + before do + spawn_comment_model + spawn_commenter_model 'User' + spawn_commentable_model 'Article' + + run_migration do + create_table(:users, force: true) + create_table(:articles, force: true) + end + end + + let(:errors) do + subject.valid? + subject.errors.full_messages + end + + describe :validates_comment do + subject { Comment.new } + it { expect(errors).to include("Comment can't be blank") } + end + + describe :validates_commenter_presence do + subject { Comment.new } + it { expect(errors).to include("Commenter can't be blank") } + end + + describe :validates_commentable_presence do + subject { Comment.new } + it { expect(errors).to include("Commentable can't be blank") } + end + + describe :validates_commentable do + subject { Comment.new(commentable: User.new) } + it { expect(errors).to include("Commentable is invalid") } + end + end + describe :ClassMethods do describe :create do context 'through general `comments` association' do before do spawn_comment_model @@ -106,8 +144,27 @@ let(:create_comment!) { commentable.photos_comments.create(commenter: commenter, comment: 'Booya') } it { expect { create_comment! }.to change { commentable.reload.photos_comments_count }.from(0).to(1) } it { expect { create_comment! }.to_not change { commentable.reload.videos_comments_count } } it { expect { create_comment! }.to change { commentable.reload.comments_count }.from(0).to(1) } + end + end + + describe :ensure_valid_role_for_commentable do + before do + spawn_comment_model + spawn_commenter_model 'User' + + run_migration do + create_table(:users, force: true) + end + end + + let(:commenter) { User.create } + + context 'without associated commentable' do + let(:comment) { Comment.new(commenter: commenter, comment: 'Booya') } + + it { expect { comment.valid? }.to_not raise_error } end end end