-
Notifications
You must be signed in to change notification settings - Fork 8
/
cc_statements_controller_test.rb
executable file
·69 lines (58 loc) · 2.1 KB
/
cc_statements_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
69
require 'test_helper'
class CcStatementsControllerTest < ActionController::TestCase
setup do
@user = users :User_1
sign_in @user
@cc_statement = cc_statements(:CcStatement_1)
@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_statement" do
assert_difference('CcStatement.count') do
post :create, format: :json,
params: {
cc_statement: {
instrument_id: @instrument.id,
literal: @cc_statement.literal,
type: 'statement',
parent: {
id: @instrument.cc_sequences.first.id,
type: 'sequence'
}
},
instrument_id: @instrument.id
}
end
assert_response :success
end
test "should show cc_statement" do
get :show, format: :json, params: { instrument_id: @instrument.id, id: @cc_statement }
assert_response :success
end
test "should update cc_statement" do
patch :update, format: :json, params: { instrument_id: @instrument.id, id: @cc_statement, cc_statement: {literal: @cc_statement.literal, parent: {
id: @instrument.cc_sequences.first.id,
type: 'sequence'
}} }
assert_response :success
assert_equal @cc_statement.reload.parent, @instrument.cc_sequences.first
end
test "should update cc_statement when parent type matches class name" do
patch :update, format: :json, params: { instrument_id: @instrument.id, id: @cc_statement, cc_statement: {literal: @cc_statement.literal, parent: {
id: @instrument.cc_sequences.first.id,
type: 'CcSequence'
}} }
assert_response :success
assert_equal @cc_statement.reload.parent, @instrument.cc_sequences.first
end
test "should destroy cc_statement" do
assert_difference('CcStatement.count', -1) do
delete :destroy, format: :json, params: { instrument_id: @instrument.id, id: @cc_statement.id }
end
assert_response :success
end
end