require "test_helper"

class CommitsControllerTest < ActionController::TestCase
  before do
    goal  = create :goal, points: 10
    round = create :round, :open
    user  = create :user, :auth_token => 'dah123rty', goal: goal
    5.times.each do |i|
      create :commit, user: user, commit_date: Date.today, message: "commit_#{i}"
    end
    sign_in user
  end
  
  def test_index
    get :index
    assert_response :success
    assert_template :index
    assert_template partial: '_commits_table'
    assert_template partial: '_commits'
    assert_equal assigns(:commits).count, 5
  end
  
  test 'should display commits between two dates' do
    get :index, {from: Date.yesterday - 1, to: Date.yesterday}
    assert_equal assigns(:commits).count, 0
  end
  
  test 'should search commits by search query' do
    get :index, {query: 'commit_1'}
    assert_equal assigns(:commits).count, 1
  end
  
  test 'should display commits between two dates and search by query' do
    get :index, {from: Date.yesterday - 1, to: Date.yesterday, query: 'commit'}
    assert_equal assigns(:commits).count, 0
  end
end

require "test_helper"

class CommitsControllerTest < ActionController::TestCase
  before do
    user  = create :user, :auth_token => 'dah123rty'
    5.times.each do |i|
      create :commit, user: user, commit_date: Date.today, message: "commit_#{i}"
    end
    sign_in user
  end
  
  def test_index
    get :index
    assert_response :success
    assert_template :index
    assert_template partial: '_commits_table'
    assert_template partial: '_commits'
    assert_equal assigns(:commits).count, 5
  end
  
  test 'should display commits between two dates' do
    get :index, {from: Date.yesterday - 1, to: Date.yesterday}
    assert_equal assigns(:commits).count, 0
  end
  
  test 'should search commits by search query' do
    get :index, {query: 'commit_1'}
    assert_equal assigns(:commits).count, 1
  end
  
  test 'should display commits between two dates and search by query' do
    get :index, {from: Date.yesterday - 1, to: Date.yesterday, query: 'commit'}
    assert_equal assigns(:commits).count, 0
  end
end

Fix test cases of commits controller
Fix test cases of commits controller
