Sha256: 41f66d6c58fda376d4f3ccd6ab812d95a6abbd6c408cd414a62e591aeb5d755d

Contents?: true

Size: 1.36 KB

Versions: 62

Compression:

Stored size: 1.36 KB

Contents

require 'test_helper'

module Workarea
  module Admin
    class CommentableViewModelTest < TestCase
      class FooViewModel < ApplicationViewModel
        include CommentableViewModel
      end

      def page
        @page ||= create_page
      end

      def test_has_comments?
        view_model = FooViewModel.new(page)
        refute(view_model.has_comments?)

        create_comment(commentable: page)
        view_model = FooViewModel.new(page)
        assert(view_model.has_comments?)
      end

      def test_new_comments_for?
        user = create_user(admin: true)
        comment = create_comment(commentable: page)

        view_model = FooViewModel.new(page)
        assert(view_model.new_comments_for?(user))

        comment_two = create_comment(commentable: page)
        comment.update(viewed_by_ids: [user.id])

        view_model = FooViewModel.new(page)
        assert(view_model.new_comments_for?(user))

        comment_two.update(viewed_by_ids: [user.id])

        view_model = FooViewModel.new(page)
        refute(view_model.new_comments_for?(user))
      end

      def test_comment_count
        view_model = FooViewModel.new(page)
        assert_equal(0, view_model.comment_count)

        Array.new(3) { create_comment(commentable: page) }
        view_model = FooViewModel.new(page)
        assert_equal(3, view_model.comment_count)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.4.27 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.4 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.26 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.3 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.25 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.2 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.24 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.1 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.23 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.22 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.0 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.21 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.0.beta.1 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.20 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.19 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.18 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.17 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.16 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.15 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.14 test/view_models/workarea/admin/commentable_view_model_test.rb