<commit_before>require "test_helper"

class TypusUserRolesTest < ActiveSupport::TestCase

  test "configuration roles" do
    assert_equal %w(admin designer disabled editor), Typus::Configuration.roles.map(&:first).sort
  end

  context "admin" do

    setup do
      @typus_user = FactoryGirl.create(:typus_user)
    end

    should "verify models access" do
      expected = ["AdminUser",
                  "Article::Entry",
                  "Asset",
                  "Bird",
                  "Case",
                  "Category",
                  "Comment",
                  "DeviseUser",
                  "Dog",
                  "Entry",
                  "EntryBulk",
                  "EntryDefault",
                  "EntryTrash",
                  "Git",
                  # "Hit",
                  "ImageHolder",
                  "Invoice",
                  "Order",
                  "Page",
                  "Post",
                  "Project",
                  "ProjectCollaborator",
                  "ReadOnlyEntry",
                  "Status",
                  "Task",
                  "TypusUser",
                  "User",
                  "View",
                  "WatchDog"]
      assert_equal expected, @typus_user.resources.map(&:first).sort
    end

    should "verify resources without actions related are removed" do
      pending
      assert !@typus_user.resources.map(&:first).include?('Order')
    end

    should "have access to all actions on models" do
      models = %w(Asset Category Comment Page Post TypusUser View)
      %w(create read update destroy).each { |a| models.each { |m| assert @typus_user.can?(a, m) } }
    end

    should "verify we can perform action on resource" do
      assert @typus_user.can?('index', 'Status', { :special => true })
    end

    should "verify we cannot perform action on resource" do
      assert @typus_user.cannot?('show', 'Status', { :special => true })
    end

    should "verify we cannot perform actions on resources which don't have that action defined" do
      pending
      assert @typus_user.cannot?('index', 'Order')
    end

  end

  context "editor" do
<commit_msg>Fixed pending tests for Ruby 1.8.7-p352<commit_after>require "test_helper"

class TypusUserRolesTest < ActiveSupport::TestCase

  test "configuration roles" do
    assert_equal %w(admin designer disabled editor), Typus::Configuration.roles.map(&:first).sort
  end

  context "admin" do

    setup do
      @typus_user = FactoryGirl.create(:typus_user)
    end

    should "verify models access" do
      expected = ["AdminUser",
                  "Article::Entry",
                  "Asset",
                  "Bird",
                  "Case",
                  "Category",
                  "Comment",
                  "DeviseUser",
                  "Dog",
                  "Entry",
                  "EntryBulk",
                  "EntryDefault",
                  "EntryTrash",
                  "Git",
                  # "Hit",
                  "ImageHolder",
                  "Invoice",
                  "Order",
                  "Page",
                  "Post",
                  "Project",
                  "ProjectCollaborator",
                  "ReadOnlyEntry",
                  "Status",
                  "Task",
                  "TypusUser",
                  "User",
                  "View",
                  "WatchDog"]
      assert_equal expected, @typus_user.resources.map(&:first).sort
    end

    should "verify resources without actions related are removed" do
      pending do
        assert !@typus_user.resources.map(&:first).include?('Order')
      end
    end

    should "have access to all actions on models" do
      models = %w(Asset Category Comment Page Post TypusUser View)
      %w(create read update destroy).each { |a| models.each { |m| assert @typus_user.can?(a, m) } }
    end

    should "verify we can perform action on resource" do
      assert @typus_user.can?('index', 'Status', { :special => true })
    end

    should "verify we cannot perform action on resource" do
      assert @typus_user.cannot?('show', 'Status', { :special => true })
    end

    should "verify we cannot perform actions on resources which don't have that action defined" do
      pending do
        assert @typus_user.cannot?('index', 'Order')
      end
    end

  end

  context "editor" do

{'fraction_non_alphanumeric': 0.1035031847133758, 'fraction_numerical': 0.001364877161055505, 'mean_word_length': 1.5698421975452952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5818580', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1108, 'n_words': 329}