Sha256: 1f09abde91ea1bda9017fabf8051394e7d4b907c6c5654080363c75b271674ec

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe Parole::Commentable do
  describe 'general `comments` relation' do
    let(:relation_class) { ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Comment }

    context 'without defined roles' do
      before do
        spawn_comment_model
        spawn_commentable_model 'Article'

        run_migration do
          create_table(:articles, force: true)
        end
      end

      it { expect(Article.create.comments).to be_instance_of(ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Comment) }
      it { expect(Article.create.comments.new.role).to be_blank }
    end

    context 'with roles' do
      before do
        spawn_comment_model
        spawn_commentable_model 'Article' do
          acts_as_commentable roles: [:photos, :videos]
        end

        run_migration do
          create_table(:articles, force: true)
        end
      end

      it { expect(Article.create.comments).to be_instance_of(relation_class) }
      it { expect(Article.create.photos_comments).to be_instance_of(relation_class) }
      it { expect(Article.create.videos_comments).to be_instance_of(relation_class) }
      it { expect(Article.create.comments.new.role).to be_blank }
      it { expect(Article.create.photos_comments.new.role).to eql 'photos' }
      it { expect(Article.create.videos_comments.new.role).to eql 'videos' }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
parole-0.1.4 spec/parole/commentable_spec.rb
parole-0.1.3 spec/parole/commentable_spec.rb
parole-0.1.2 spec/parole/commentable_spec.rb