|
6 | 6 | let(:rewriter_name) { 'rails/convert_active_record_dirty_5_0_to_5_1' }
|
7 | 7 | let(:fake_file_path) { 'app/models/post.rb' }
|
8 | 8 | let(:schema_content) { <<~EOS }
|
9 |
| - ActiveRecord::Schema.define(version: 20140211112752) do |
10 |
| - create_table "posts", force: true do |t| |
11 |
| - t.string "title" |
12 |
| - t.string "summary" |
13 |
| - t.boolean "status" |
14 |
| - t.timestamps |
15 |
| - end |
| 9 | + ActiveRecord::Schema.define(version: 20140211112752) do |
| 10 | + create_table "posts", force: true do |t| |
| 11 | + t.string "title" |
| 12 | + t.string "summary" |
| 13 | + t.boolean "status" |
| 14 | + t.timestamps |
16 | 15 | end
|
| 16 | + end |
17 | 17 | EOS
|
18 | 18 |
|
19 | 19 | let(:test_content) { <<~EOS }
|
20 |
| - class Post < ActiveRecord::Base |
21 |
| - before_create :call_before_create |
22 |
| - before_update :call_before_update, unless: :title_changed? |
23 |
| - before_save :call_before_save, if: -> { status_changed? || summary_changed? } |
24 |
| - after_create :call_after_create |
25 |
| - after_update :call_after_update, unless: :title_changed? |
26 |
| - after_save :call_after_save, if: -> { status_changed? || summary_changed? } |
| 20 | + class Post < ActiveRecord::Base |
| 21 | + before_create :call_before_create |
| 22 | + before_update :call_before_update, unless: :title_changed? |
| 23 | + before_save :call_before_save, if: -> { status_changed? || summary_changed? } |
| 24 | + after_create :call_after_create |
| 25 | + after_update :call_after_update, unless: :title_changed? |
| 26 | + after_save :call_after_save, if: -> { status_changed? || summary_changed? } |
27 | 27 |
|
28 |
| - before_save do |
29 |
| - if title_changed? |
30 |
| - end |
| 28 | + before_save do |
| 29 | + if title_changed? |
31 | 30 | end
|
| 31 | + end |
32 | 32 |
|
33 |
| - def call_before_create |
34 |
| - if title_changed? |
35 |
| - changes |
36 |
| - end |
| 33 | + def call_before_create |
| 34 | + if title_changed? |
| 35 | + changes |
37 | 36 | end
|
| 37 | + end |
38 | 38 |
|
39 |
| - def call_after_create |
40 |
| - if title_changed? |
41 |
| - changes |
42 |
| - end |
| 39 | + def call_after_create |
| 40 | + if title_changed? |
| 41 | + changes |
43 | 42 | end
|
44 | 43 | end
|
| 44 | + end |
45 | 45 | EOS
|
46 | 46 |
|
47 | 47 | let(:test_rewritten_content) { <<~EOS }
|
48 |
| - class Post < ActiveRecord::Base |
49 |
| - before_create :call_before_create |
50 |
| - before_update :call_before_update, unless: :will_save_change_to_title? |
51 |
| - before_save :call_before_save, if: -> { will_save_change_to_status? || will_save_change_to_summary? } |
52 |
| - after_create :call_after_create |
53 |
| - after_update :call_after_update, unless: :saved_change_to_title? |
54 |
| - after_save :call_after_save, if: -> { saved_change_to_status? || saved_change_to_summary? } |
| 48 | + class Post < ActiveRecord::Base |
| 49 | + before_create :call_before_create |
| 50 | + before_update :call_before_update, unless: :will_save_change_to_title? |
| 51 | + before_save :call_before_save, if: -> { will_save_change_to_status? || will_save_change_to_summary? } |
| 52 | + after_create :call_after_create |
| 53 | + after_update :call_after_update, unless: :saved_change_to_title? |
| 54 | + after_save :call_after_save, if: -> { saved_change_to_status? || saved_change_to_summary? } |
55 | 55 |
|
56 |
| - before_save do |
57 |
| - if will_save_change_to_title? |
58 |
| - end |
| 56 | + before_save do |
| 57 | + if will_save_change_to_title? |
59 | 58 | end
|
| 59 | + end |
60 | 60 |
|
61 |
| - def call_before_create |
62 |
| - if will_save_change_to_title? |
63 |
| - changes_to_save |
64 |
| - end |
| 61 | + def call_before_create |
| 62 | + if will_save_change_to_title? |
| 63 | + changes_to_save |
65 | 64 | end
|
| 65 | + end |
66 | 66 |
|
67 |
| - def call_after_create |
68 |
| - if saved_change_to_title? |
69 |
| - saved_changes |
70 |
| - end |
| 67 | + def call_after_create |
| 68 | + if saved_change_to_title? |
| 69 | + saved_changes |
71 | 70 | end
|
72 | 71 | end
|
| 72 | + end |
73 | 73 | EOS
|
74 | 74 |
|
75 | 75 | before do
|
|
0 commit comments