@@ -13,54 +13,54 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
1313
1414 assert_file 'app/controllers/posts_controller.rb' do |content |
1515 assert_instance_method :index , content do |m |
16- assert_match / @posts = Post\. all/ , m
16+ assert_match %r{ @posts = Post\. all} , m
1717 end
1818
1919 assert_instance_method :show , content do |m |
2020 assert m . blank?
2121 end
2222
2323 assert_instance_method :new , content do |m |
24- assert_match / @post = Post\. new/ , m
24+ assert_match %r{ @post = Post\. new} , m
2525 end
2626
2727 assert_instance_method :edit , content do |m |
2828 assert m . blank?
2929 end
3030
3131 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
3838 end
3939
4040 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
4545 end
4646
4747 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
5151 end
5252
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
5555 end
5656 end
5757
5858 test 'dont use require and permit if there are no attributes' do
5959 run_generator %w( Post )
6060
6161 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
6464 end
6565 end
6666end
0 commit comments