From 38f4d0524f9175c015e8241b053191dd8ca4390d Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 15 May 2018 20:41:48 +0200 Subject: [PATCH] Add spec for sequential creations and deletes Closes SCI-2320. --- ..._table_state_column_update_service_spec.rb | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/spec/services/repository_table_state_column_update_service_spec.rb b/spec/services/repository_table_state_column_update_service_spec.rb index 010c575e0..b3e50c9b7 100644 --- a/spec/services/repository_table_state_column_update_service_spec.rb +++ b/spec/services/repository_table_state_column_update_service_spec.rb @@ -293,4 +293,78 @@ describe RepositoryTableStateColumnUpdateService do ) end end + + describe 'consequential creations and removals' do + let!(:repository_column_3) do + create :repository_column, name: 'My column 3', + repository: repository, + data_type: :RepositoryTextValue + end + let!(:repository_column_4) do + create :repository_column, name: 'My column 4', + repository: repository, + data_type: :RepositoryTextValue + end + let!(:initial_state) do + state = RepositoryTableStateService.new(user_1, repository) + .create_default_state + state.state['order'] = {'0' => ['8', 'desc']} + (0..9).each do |idx| + state.state['columns'][idx.to_s]['search']['search'] = "search_#{idx}" + end + state.state['ColReorder'] = + ['0', '1', '2', '9', '8', '4', '7', '3', '5', '6'] + RepositoryTableStateService.new(user_1, repository).update_state( + state.state + ) + state + end + + it 'should update state accordingly' do + expect(initial_state).to be_valid_repository_table_state(4) + + service.update_states_with_new_column(repository) + + state = RepositoryTableStateService.new(user_1, repository).load_state + expect(state).to be_valid_repository_table_state(5) + expect(state.state['ColReorder']).to eq( + ['0', '1', '2', '9', '8', '4', '7', '3', '5', '6', '10'] + ) + + service.update_states_with_removed_column(repository, '7') + + state = RepositoryTableStateService.new(user_1, repository).load_state + expect(state).to be_valid_repository_table_state(4) + expect(state.state['ColReorder']).to eq( + ['0', '1', '2', '8', '7', '4', '3', '5', '6', '9'] + ) + expect(state.state['order']).to eq ({'0' => ['7', 'desc']}) + + service.update_states_with_removed_column(repository, '7') + + state = RepositoryTableStateService.new(user_1, repository).load_state + expect(state).to be_valid_repository_table_state(3) + expect(state.state['ColReorder']).to eq( + ['0', '1', '2', '7', '4', '3', '5', '6', '8'] + ) + expect(state.state['order']).to eq ({'0' => ['2', 'asc']}) + + service.update_states_with_removed_column(repository, '7') + + state = RepositoryTableStateService.new(user_1, repository).load_state + expect(state).to be_valid_repository_table_state(2) + expect(state.state['ColReorder']).to eq( + ['0', '1', '2', '4', '3', '5', '6', '7'] + ) + + service.update_states_with_new_column(repository) + service.update_states_with_new_column(repository) + + state = RepositoryTableStateService.new(user_1, repository).load_state + expect(state).to be_valid_repository_table_state(4) + expect(state.state['ColReorder']).to eq( + ['0', '1', '2', '4', '3', '5', '6', '7', '8', '9'] + ) + end + end end \ No newline at end of file