<commit_before>require 'spec_helper'
describe Rating do
  let(:application) { FactoryGirl.build_stubbed(:application) }

  describe 'associations' do
    it { is_expected.to belong_to(:user) }
    it { is_expected.to belong_to(:application) }
    it { is_expected.to belong_to(:rateable) }

    let(:user) { FactoryGirl.build_stubbed(:user) }

    it 'should only allow for one rating per user and rateable' do
      Rating.create(rateable: application, user: user)
      expect{ Rating.create!(rateable: application, user: user) }.to raise_error(ActiveRecord::RecordInvalid)
    end
  end

  describe 'scopes' do
    describe 'by' do
      it 'should return the rating for the given user' do
        user = create(:user)
        rating = create(:rating, user: user, rateable: application)
        expect(Rating.by(user).first).to eq(rating)
      end
    end
  end
  describe '.user_names' do
    let(:users) { create_list :user, 3 }
    let(:user_names) { users.map(&:name) }

    before { users.each{|user| create(:rating, user: user, rateable: application) } }

    it 'returns names of all users who submitted a rating' do
      expect(Rating.user_names).to match_array user_names
    end

    it 'excludes other users' do
      user = create :user
      expect(Rating.user_names).not_to include user.name
    end
  end
  describe '#points' do
    it 'should add up some points given through valid fields' do
      rating = create(:rating, rateable: application)
      rating.diversity = 0
      rating.skills = 10
      rating.save

      # after weights this hsould be:
      expect(rating.points).to eq(1.5)
    end
  end
end<commit_msg>fix rating spec<commit_after>require 'spec_helper'
describe Rating do
  let(:application) { FactoryGirl.build_stubbed(:application) }

  describe 'associations' do
    it { is_expected.to belong_to(:user) }
    it { is_expected.to belong_to(:application) }
    it { is_expected.to belong_to(:rateable) }

    let(:user) { FactoryGirl.build_stubbed(:user) }

    it 'should only allow for one rating per user and rateable' do
      Rating.create(rateable: application, user: user)
      expect{ Rating.create!(rateable: application, user: user) }.to raise_error(ActiveRecord::RecordInvalid)
    end
  end

  describe 'scopes' do
    describe 'by' do
      it 'should return the rating for the given user' do
        user = create(:user)
        rating = create(:rating, user: user, rateable: application)
        expect(Rating.by(user).first).to eq(rating)
      end
    end
  end
  describe '.user_names' do
    let(:users) { create_list :user, 3 }
    let(:user_names) { users.map(&:name) }

    before { users.each{|user| create(:rating, user: user, rateable: application) } }

    it 'returns names of all users who submitted a rating' do
      expect(Rating.user_names).to match_array user_names
    end

    it 'excludes other users' do
      user = create :user
      expect(Rating.user_names).not_to include user.name
    end
  end
  describe '#points' do
    it 'should add up some points given through valid fields' do
      rating = create(:rating, rateable: application)
      rating.diversity = 1
      rating.save

      # after weights this should be:
      expect(rating.points).to be > 0
    end
  end
end
{'fraction_non_alphanumeric': 0.10042865890998164, 'fraction_numerical': 0.0027556644213104714, 'mean_word_length': 3.1564885496183206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3071332', 'n_tokens_mistral': 1011, 'n_tokens_neox': 972, 'n_words': 304}