-
Notifications
You must be signed in to change notification settings - Fork 8
/
cc_conditions_controller_test.rb
executable file
·68 lines (57 loc) · 2.24 KB
/
cc_conditions_controller_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'test_helper'
class CcConditionsControllerTest < ActionController::TestCase
setup do
@user = users :User_1
sign_in @user
@cc_condition = cc_conditions(:CcCondition_9)
@instrument = instruments(:Instrument_1)
end
test "should get index" do
get :index, format: :json, params: { instrument_id: @instrument.id }
assert_response :success
assert_not_nil assigns(:collection)
end
test "should create cc_condition" do
assert_difference('CcCondition.count') do
post :create, format: :json,
params: { cc_condition: {
instrument_id: @instrument.id,
literal: @cc_condition.literal,
logic: @cc_condition.logic,
type: 'condition',
parent: {
id: @cc_condition.parent.id,
type: 'sequence'
}
},
instrument_id: @instrument.id }
end
assert_response :success
end
test "should show cc_condition" do
get :show, format: :json, params: { instrument_id: @instrument.id, id: @cc_condition }
assert_response :success
end
test "should update cc_condition" do
patch :update, format: :json, params: { instrument_id: @instrument.id, id: @cc_condition, cc_condition: {literal: @cc_condition.literal, logic: @cc_condition.logic, parent: {
id: @instrument.cc_sequences.first.id,
type: 'sequence'
}} }
assert_response :success
assert_equal @cc_condition.reload.parent, @instrument.cc_sequences.first
end
test "should update cc_condition when parent type matches class name" do
patch :update, format: :json, params: { instrument_id: @instrument.id, id: @cc_condition, cc_condition: {literal: @cc_condition.literal, logic: @cc_condition.logic, parent: {
id: @instrument.cc_sequences.first.id,
type: 'CcSequence'
}} }
assert_response :success
assert_equal @cc_condition.reload.parent, @instrument.cc_sequences.first
end
test "should destroy cc_condition" do
assert_difference('CcCondition.count', -1) do
delete :destroy, format: :json, params: { instrument_id: @instrument.id, id: @cc_condition.id }
end
assert_response :success
end
end