<commit_before>require 'rails_helper'

module FlyoverComments
  RSpec.describe Authorization do
    class Widget
      include FlyoverComments::Authorization
    end

    describe "can_delete_flyover_comment?" do
      let(:user){ Ident::User.new }
      let(:comment){ double(user: user) }

      it "calls can_delete_flyover_comment? on the passed user if the user defines it" do
        def user.can_delete_flyover_comment?(comment)
          true
        end

        expect(user).to receive(:can_delete_flyover_comment?).with(comment)
        Widget.new.can_delete_flyover_comment?(comment, user)
      end

      it "returns true if user#can_delete_flyover_comment? isn't defined and the comment's user is the passed user" do
        is_allowed = Widget.new.can_delete_flyover_comment?(comment, user)
        expect(is_allowed).to eq(true)
      end

      it "returns false if user#can_delete_flyover_comment? isn't defined and the comment's user is not the passed user" do
        is_allowed = Widget.new.can_delete_flyover_comment?(comment, Ident::User.new)
        expect(is_allowed).to eq(false)
      end
    end

    describe "can_create_flyover_comment?" do
      let(:user){ Ident::User.new }
      let(:comment){ double(user: user) }

      it "calls can_create_flyover_comment? on the passed user if the user defines it" do
        def user.can_create_flyover_comment?(comment)
          true
        end

        expect(user).to receive(:can_create_flyover_comment?).with(comment)
        Widget.new.can_create_flyover_comment?(comment, user)
      end

      it "returns true if user#can_create_flyover_comment? isn't defined and the comment's user is the passed user" do
        is_allowed = Widget.new.can_create_flyover_comment?(comment, user)
        expect(is_allowed).to eq(true)
      end

      it "returns false if user#can_create_flyover_comment? isn't defined and the comment's user is not the passed user" do
        is_allowed = Widget.new.can_create_flyover_comment?(comment, Ident::User.new)
        expect(is_allowed).to eq(false)
      end
    end

    describe "can_flag_flyover_comment?" do
      let(:user){ Ident::User.new }
      let(:comment){ double(user: user) }

      it "calls can_flag_flyover_comment? on the passed user if the user defines it" do
        def user.can_flag_flyover_comment?(comment)
          true
        end

        expect(user).to receive(:can_flag_flyover_comment?).with(comment)
        Widget.new.can_flag_flyover_comment?(comment, user)
      end

      it "returns true if user#can_flag_flyover_comment? isn't defined and the comment's user is the passed user" do
        is_allowed = Widget.new.can_flag_flyover_comment?(comment, user)
        expect(is_allowed).to eq(true)
      end

      it "returns false if user#can_flag_flyover_comment? isn't defined and the comment's user is not the passed user" do
        is_allowed = Widget.new.can_flag_flyover_comment?(comment, Ident::User.new)
        expect(is_allowed).to eq(false)
      end
    end

  end
end
<commit_msg>modifying the tests to account for allowing logged in people to flag<commit_after>require 'rails_helper'

module FlyoverComments
  RSpec.describe Authorization do
    class Widget
      include FlyoverComments::Authorization
    end

    describe "can_delete_flyover_comment?" do
      let(:user){ Ident::User.new }
      let(:comment){ double(user: user) }

      it "calls can_delete_flyover_comment? on the passed user if the user defines it" do
        def user.can_delete_flyover_comment?(comment)
          true
        end

        expect(user).to receive(:can_delete_flyover_comment?).with(comment)
        Widget.new.can_delete_flyover_comment?(comment, user)
      end

      it "returns true if user#can_delete_flyover_comment? isn't defined and the comment's user is the passed user" do
        is_allowed = Widget.new.can_delete_flyover_comment?(comment, user)
        expect(is_allowed).to eq(true)
      end

      it "returns false if user#can_delete_flyover_comment? isn't defined and the comment's user is not the passed user" do
        is_allowed = Widget.new.can_delete_flyover_comment?(comment, Ident::User.new)
        expect(is_allowed).to eq(false)
      end
    end

    describe "can_create_flyover_comment?" do
      let(:user){ Ident::User.new }
      let(:comment){ double(user: user) }

      it "calls can_create_flyover_comment? on the passed user if the user defines it" do
        def user.can_create_flyover_comment?(comment)
          true
        end

        expect(user).to receive(:can_create_flyover_comment?).with(comment)
        Widget.new.can_create_flyover_comment?(comment, user)
      end

      it "returns true if user#can_create_flyover_comment? isn't defined and the comment's user is the passed user" do
        is_allowed = Widget.new.can_create_flyover_comment?(comment, user)
        expect(is_allowed).to eq(true)
      end

      it "returns false if user#can_create_flyover_comment? isn't defined and the comment's user is not the passed user" do
        is_allowed = Widget.new.can_create_flyover_comment?(comment, Ident::User.new)
        expect(is_allowed).to eq(false)
      end
    end

    describe "can_flag_flyover_comment?" do
      let(:user){ Ident::User.new }
      let(:comment){ double(user: user) }

      it "calls can_flag_flyover_comment? on the passed user if the user defines it" do
        def user.can_flag_flyover_comment?(comment)
          true
        end

        expect(user).to receive(:can_flag_flyover_comment?).with(comment)
        Widget.new.can_flag_flyover_comment?(comment, user)
      end

      it "returns true if user#can_flag_flyover_comment? isn't defined and the user is logged in" do
        is_allowed = Widget.new.can_flag_flyover_comment?(comment, user)
        expect(is_allowed).to eq(true)
      end

    end

  end
end

{'fraction_non_alphanumeric': 0.08164653852696037, 'fraction_numerical': 0.0, 'mean_word_length': 3.2241379310344827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7241680', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1757, 'n_words': 470}