|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe AnnotateRb::ModelAnnotator::AnnotationDiffGenerator do |
| 4 | + include AnnotateTestHelpers |
| 5 | + |
4 | 6 | def test_columns_match_expected |
5 | | - remove_whitespace = Proc.new { |str| str.delete(" \t\r\n") } |
| 7 | + remove_whitespace = Proc.new { |str| str.delete(" \t\r\n") } |
6 | 8 |
|
7 | 9 | resulting_current_columns_data = subject.current_columns.map(&remove_whitespace) |
8 | 10 | expected_current_columns_data = current_columns.map(&remove_whitespace) |
@@ -142,5 +144,53 @@ class User < ApplicationRecord |
142 | 144 | expect(subject.changed?).to eq(true) |
143 | 145 | end |
144 | 146 | end |
| 147 | + |
| 148 | + context 'when model file has existing annotations with column multi-byte comments' do |
| 149 | + let(:annotation_block) do |
| 150 | + klass = mock_class(:users, |
| 151 | + :id, |
| 152 | + [ |
| 153 | + mock_column(:id, :bigint, comment: 'ID'), |
| 154 | + mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'), |
| 155 | + ], |
| 156 | + [], |
| 157 | + []) |
| 158 | + options = AnnotateRb::Options.from({}) |
| 159 | + AnnotateRb::ModelAnnotator::AnnotationBuilder.new(klass, options).build |
| 160 | + end |
| 161 | + |
| 162 | + let(:file_content) do |
| 163 | + <<~FILE |
| 164 | + # == Schema Information |
| 165 | + # |
| 166 | + # Table name: users |
| 167 | + # |
| 168 | + # id(ID) :bigint not null, primary key |
| 169 | + # |
| 170 | + class User < ApplicationRecord |
| 171 | + end |
| 172 | + FILE |
| 173 | + end |
| 174 | + |
| 175 | + let(:current_columns) do |
| 176 | + [ |
| 177 | + "# id(ID) :bigint not null, primary key", |
| 178 | + "# Table name: users" |
| 179 | + ] |
| 180 | + end |
| 181 | + let(:new_columns) do |
| 182 | + [ |
| 183 | + "# id(ID) :bigint not null, primary key", |
| 184 | + "# active(ACTIVE) :boolean not null", |
| 185 | + "# Table name: users" |
| 186 | + ] |
| 187 | + end |
| 188 | + |
| 189 | + it 'returns an AnnotationDiff object with the expected old and new columns' do |
| 190 | + test_columns_match_expected |
| 191 | + |
| 192 | + expect(subject.changed?).to eq(true) |
| 193 | + end |
| 194 | + end |
145 | 195 | end |
146 | 196 | end |
0 commit comments