<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

describe ChatController do
  describe "発言投稿時は" do
    before do
      user = User.new
      user.save
      session[:current_user_id] = user.id
    end

    it "一件messageが増える" do
      lambda {
        room = Room.new
        room.save!
        message = 'テストメッセージ'
        post :message, {:room_id => room.id, :message => message}
      }.should change(Message.all.records, :size).by(1)
    end

    it "部屋がない場合はエラーメッセージとなる" do
      room = Room.new
      room.save
      room.delete
      lambda {
        post(:message, {:room_id => room.id, :message => 'テストメッセージ'})
      }.should raise_error
    end
  end

  describe "発言一覧時は" do
    it "デフォルトで該当する部屋のメッセージの20件を取得する" do
      room = Room.new
      room.save
      50.times do
        Message.new(:room => room).save
      end
      get :room, {:id => room.id}
      assigns[:messages].records.size.should == 20
    end
  end

  describe "発言更新時は" do
    it "該当メッセージの内容が更新される" do
      message = Message.new(:body => 'init')
      message.save
      get :update_message_on_the_spot, {:id => message.id, :value => 'modified'}
      Message.find(message.id).body.should == 'modified'
    end
  end

  describe "発言削除時は" do
    it "一件messageが減る" do
      pending
    end
    it "部屋がない場合はエラー" do
      room = Room.new
      room.save
      room.delete if room
      pending
      post :delete, {:room_id => 1, :message_id => 1}
    end
  end

  describe "部屋作成時は" do
    it "一件roomが増える" do
      title = 'テスト部屋'
      post :room, {:room => {:title => title}}
      assigns[:room].title.should == title
    end
  end
end
<commit_msg>chat controller の spec をさらに追加 refs #338<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe ChatController do
  describe "発言投稿時は" do
    before do
      user = User.new
      user.save
      session[:current_user_id] = user.id
    end

    it "一件messageが増える" do
      lambda {
        room = Room.new
        room.save!
        message = 'テストメッセージ'
        post :message, {:room_id => room.id, :message => message}
      }.should change(Message.all.records, :size).by(1)
    end

    it "部屋がない場合はエラーメッセージとなる" do
      room = Room.new
      room.save
      room.delete
      lambda {
        post(:message, {:room_id => room.id, :message => 'テストメッセージ'})
      }.should raise_error
    end
  end

  describe "発言一覧時は" do
    it "デフォルトで該当する部屋のメッセージの20件を取得する" do
      room = Room.new
      room.save
      50.times do
        Message.new(:room => room).save
      end
      get :room, {:id => room.id}
      assigns[:messages].records.size.should == 20
    end
  end

  describe "発言更新時は" do
    it "該当メッセージの内容が更新される" do
      message = Message.new(:body => 'init')
      message.save
      get :update_message_on_the_spot, {:id => message.id, :value => 'modified'}
      Message.find(message.id).body.should == 'modified'
    end
  end

  describe "発言削除時は" do
    it "一件messageが減る" do
      pending
    end
    it "部屋がない場合はエラー" do
      room = Room.new
      room.save
      room.delete if room
      pending
      post :delete, {:room_id => 1, :message_id => 1}
    end
  end

  describe "部屋作成時は" do
    it "一件roomが増える" do
      title = 'テスト部屋'
      post :room, {:room => {:title => title}}
      assigns[:room].title.should == title
    end
  end

  it "index アクセス時は削除されていない部屋が表示される" do
    Room.all.each {|room| room.delete}
    room1 = Room.new.save
    room2 = Room.new(:deleted => true).save
    get :index
    assigns[:rooms].each {|room| room.deleted.should be_false}
    assigns[:rooms].records.size.should == 1
  end

  it "show アクセス時は前後n件が表示される" do
    room = Room.new
    room.save
    10.times { Message.new(:room => room).save }
    message = Message.new(:room => room)
    message.save
    10.times { Message.new(:room => room).save }
    get :show, :id => message.id, :c => 5
    assigns[:messages].size.should == 11
  end

  it "部屋の名前を変更する" do
    room = Room.new(:title => 'init')
    room.save
    get :update_attribute_on_the_spot, :id => "room__title__#{room.id}", :value => 'modified'
    Room.find(room.id).title.should == 'modified'
  end
end

{'fraction_non_alphanumeric': 0.12657308809293322, 'fraction_numerical': 0.007502420135527589, 'mean_word_length': 2.298483639265762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '3734928', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1582, 'n_words': 347}