<commit_before>require 'rails_helper'

RSpec.describe DungeonHashesController, type: :controller do
  render_views

  describe 'GET index' do
    it 'when exist' do
      user = create :user
      dungeon = create :dungeon
      dungeon_hash = create :dungeon_hash, user_id: user.id, dungeon_id: dungeon.id

      get :index, dungeon_id: dungeon.id, student_id: user.id, format: :json

      expect(json['code']).to eq(200)
      expect(json['body']['id']).to eq(dungeon_hash.id)
      expect(json['body']['user_id']).to eq(user.id)
      expect(json['body']['dungeon_id']).to eq(dungeon.id)
      expect(json['body']['dungeon_hash']).to eq('_asd')
    end

    it 'when not exist' do
      dungeon = create :dungeon
      user = create :user
      expect do
        get :index, dungeon_id: dungeon.id, student_id: user.id, format: :json
        expect(json['code']).to eq(200)
        expect(json['body']['dungeon_id']).to eq(dungeon.id)
        expect(json['body']['user_id']).to eq(user.id)
        expect(json['body']['dungeon_hash']).to eq('_')
      end.to change{ DungeonHash.count }.by (1)
    end

    it 'when user not exist' do
      user = create :user
      expect do
        get :index, dungeon_id: -1, student_id: user.id, format: :json
        expect(json['code']).to eq(200)
        expect(json['body']).to eq('')
      end.to change{ DungeonHash.count }.by (0)
    end

    it 'when dungeon not exist' do
      dungeon = create :dungeon
      expect do
        get :index, dungeon_id: dungeon.id, student_id: -1, format: :json
        expect(json['code']).to eq(200)
        expect(json['body']).to eq('')
      end.to change{ DungeonHash.count }.by (0)
    end
  end
end<commit_msg>create test for update dungeon_hash<commit_after>require 'rails_helper'

RSpec.describe DungeonHashesController, type: :controller do
  render_views

  describe 'GET index' do
    it 'when exist' do
      user = create :user
      dungeon = create :dungeon
      dungeon_hash = create :dungeon_hash, user_id: user.id, dungeon_id: dungeon.id

      get :index, dungeon_id: dungeon.id, student_id: user.id, format: :json

      expect(json['code']).to eq(200)
      expect(json['body']['id']).to eq(dungeon_hash.id)
      expect(json['body']['user_id']).to eq(user.id)
      expect(json['body']['dungeon_id']).to eq(dungeon.id)
      expect(json['body']['dungeon_hash']).to eq('_asd')
    end

    it 'when not exist' do
      dungeon = create :dungeon
      user = create :user
      expect do
        get :index, dungeon_id: dungeon.id, student_id: user.id, format: :json
        expect(json['code']).to eq(200)
        expect(json['body']['dungeon_id']).to eq(dungeon.id)
        expect(json['body']['user_id']).to eq(user.id)
        expect(json['body']['dungeon_hash']).to eq('_')
      end.to change{ DungeonHash.count }.by (1)
    end

    it 'when user not exist' do
      user = create :user
      expect do
        get :index, dungeon_id: -1, student_id: user.id, format: :json
        expect(json['code']).to eq(200)
        expect(json['body']).to eq('')
      end.to change{ DungeonHash.count }.by (0)
    end

    it 'when dungeon not exist' do
      dungeon = create :dungeon
      expect do
        get :index, dungeon_id: dungeon.id, student_id: -1, format: :json
        expect(json['code']).to eq(200)
        expect(json['body']).to eq('')
      end.to change{ DungeonHash.count }.by (0)
    end
  end

  it 'update an dungeon_hash' do
    dungeon = create :dungeon
    student = create :user
    dungeon_hash = create :dungeon_hash, dungeon_id: dungeon.id, user_id: student.id
    new_dungeon_hash = put :update, dungeon_id: dungeon.id, student_id: student.id, id: dungeon_hash.id, hash: '_a2bc', format: :json
    expect(json['code']).to eq(200)
    expect(json['body']['dungeon_id']).to eq(dungeon.id)
    expect(json['body']['user_id']).to eq(student.id)
    expect(json['body']['id']).to eq(dungeon_hash.id)
    expect(json['body']['dungeon_hash']).to eq('_a2bc')
  end

end
{'fraction_non_alphanumeric': 0.1535767883941971, 'fraction_numerical': 0.00975487743871936, 'mean_word_length': 3.1057494866529773, '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': '6433651', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1419, 'n_words': 331}