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.5.27 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.26 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.45 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.25 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.23 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.44 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.22 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.43 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.21 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.42 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.20 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.41 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.19 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.40 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.18 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.39 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.17 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.38 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.5.16 test/view_models/workarea/admin/commentable_view_model_test.rb
workarea-admin-3.4.37 test/view_models/workarea/admin/commentable_view_model_test.rb