@@ -13,54 +13,54 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
13
13
14
14
assert_file 'app/controllers/posts_controller.rb' do |content |
15
15
assert_instance_method :index , content do |m |
16
- assert_match / @posts = Post\. all/ , m
16
+ assert_match %r{ @posts = Post\. all} , m
17
17
end
18
18
19
19
assert_instance_method :show , content do |m |
20
20
assert m . blank?
21
21
end
22
22
23
23
assert_instance_method :new , content do |m |
24
- assert_match / @post = Post\. new/ , m
24
+ assert_match %r{ @post = Post\. new} , m
25
25
end
26
26
27
27
assert_instance_method :edit , content do |m |
28
28
assert m . blank?
29
29
end
30
30
31
31
assert_instance_method :create , content do |m |
32
- assert_match / @post = Post\. new\( post_params\) / , m
33
- assert_match / @post\. save/ , m
34
- assert_match / format\. html \{ redirect_to @post, notice: 'Post was successfully created\. ' \} / , m
35
- assert_match / format\. json \{ render :show, status: :created, location: @post \} / , m
36
- assert_match / format\. html \{ render :new \} / , m
37
- assert_match / format\. json \{ render json: @post\. errors, status: :unprocessable_entity \} / , m
32
+ assert_match %r{ @post = Post\. new\( post_params\) } , m
33
+ assert_match %r{ @post\. save} , m
34
+ assert_match %r{ format\. html \{ redirect_to @post, notice: 'Post was successfully created\. ' \} } , m
35
+ assert_match %r{ format\. json \{ render :show, status: :created, location: @post \} } , m
36
+ assert_match %r{ format\. html \{ render :new \} } , m
37
+ assert_match %r{ format\. json \{ render json: @post\. errors, status: :unprocessable_entity \} } , m
38
38
end
39
39
40
40
assert_instance_method :update , content do |m |
41
- assert_match / format\. html \{ redirect_to @post, notice: 'Post was successfully updated\. ' \} / , m
42
- assert_match / format\. json \{ render :show, status: :ok, location: @post \} / , m
43
- assert_match / format\. html \{ render :edit \} / , m
44
- assert_match / format\. json \{ render json: @post.errors, status: :unprocessable_entity \} / , m
41
+ assert_match %r{ format\. html \{ redirect_to @post, notice: 'Post was successfully updated\. ' \} } , m
42
+ assert_match %r{ format\. json \{ render :show, status: :ok, location: @post \} } , m
43
+ assert_match %r{ format\. html \{ render :edit \} } , m
44
+ assert_match %r{ format\. json \{ render json: @post.errors, status: :unprocessable_entity \} } , m
45
45
end
46
46
47
47
assert_instance_method :destroy , content do |m |
48
- assert_match / @post\. destroy/ , m
49
- assert_match / format\. html \{ redirect_to posts_url, notice: 'Post was successfully destroyed\. ' \} / , m
50
- assert_match / format\. json \{ head :no_content \} / , m
48
+ assert_match %r{ @post\. destroy} , m
49
+ assert_match %r{ format\. html \{ redirect_to posts_url, notice: 'Post was successfully destroyed\. ' \} } , m
50
+ assert_match %r{ format\. json \{ head :no_content \} } , m
51
51
end
52
52
53
- assert_match / def post_params/ , content
54
- assert_match / params\. require\( :post\) \. permit\( :title, :body\) / , content
53
+ assert_match %r{ def post_params} , content
54
+ assert_match %r{ params\. require\( :post\) \. permit\( :title, :body\) } , content
55
55
end
56
56
end
57
57
58
58
test 'dont use require and permit if there are no attributes' do
59
59
run_generator %w( Post )
60
60
61
61
assert_file 'app/controllers/posts_controller.rb' do |content |
62
- assert_match / def post_params/ , content
63
- assert_match / params\. fetch\( :post, { }\) / , content
62
+ assert_match %r{ def post_params} , content
63
+ assert_match %r{ params\. fetch\( :post, \{ \ }\) } , content
64
64
end
65
65
end
66
66
end
0 commit comments