Skip to content

Commit 7a16e59

Browse files
committed
Add test for annotate --routes
1 parent 1664075 commit 7a16e59

File tree

1 file changed

+85
-37
lines changed

1 file changed

+85
-37
lines changed

spec/integration/rails_5.2.4.1_spec.rb

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131

3232
let(:task_model) do
3333
patch = <<~PATCH
34-
+# == Schema Information
35-
+#
36-
+# Table name: tasks
37-
+#
38-
+# id :integer not null, primary key
39-
+# content :string
40-
+# count :integer default("0")
41-
+# status :boolean default("0")
42-
+# created_at :datetime not null
43-
+# updated_at :datetime not null
44-
+#
34+
+# == Schema Information
35+
+#
36+
+# Table name: tasks
37+
+#
38+
+# id :integer not null, primary key
39+
+# content :string
40+
+# count :integer default("0")
41+
+# status :boolean default("0")
42+
+# created_at :datetime not null
43+
+# updated_at :datetime not null
44+
+#
4545
PATCH
4646

4747
path = 'app/models/task.rb'
@@ -52,17 +52,17 @@
5252
end
5353
let(:task_test) do
5454
patch = <<~PATCH
55-
+# == Schema Information
56-
+#
57-
+# Table name: tasks
58-
+#
59-
+# id :integer not null, primary key
60-
+# content :string
61-
+# count :integer default("0")
62-
+# status :boolean default("0")
63-
+# created_at :datetime not null
64-
+# updated_at :datetime not null
65-
+#
55+
+# == Schema Information
56+
+#
57+
+# Table name: tasks
58+
+#
59+
+# id :integer not null, primary key
60+
+# content :string
61+
+# count :integer default("0")
62+
+# status :boolean default("0")
63+
+# created_at :datetime not null
64+
+# updated_at :datetime not null
65+
+#
6666
PATCH
6767

6868
path = 'test/models/task_test.rb'
@@ -73,17 +73,17 @@
7373
end
7474
let(:task_fixture) do
7575
patch = <<~PATCH
76-
+# == Schema Information
77-
+#
78-
+# Table name: tasks
79-
+#
80-
+# id :integer not null, primary key
81-
+# content :string
82-
+# count :integer default("0")
83-
+# status :boolean default("0")
84-
+# created_at :datetime not null
85-
+# updated_at :datetime not null
86-
+#
76+
+# == Schema Information
77+
+#
78+
+# Table name: tasks
79+
+#
80+
+# id :integer not null, primary key
81+
+# content :string
82+
+# count :integer default("0")
83+
+# status :boolean default("0")
84+
+# created_at :datetime not null
85+
+# updated_at :datetime not null
86+
+#
8787
PATCH
8888

8989
path = 'test/fixtures/tasks.yml'
@@ -101,10 +101,58 @@
101101
puts `#{command}`
102102

103103
expect(git.diff.entries).to contain_exactly(
104-
an_object_having_attributes(task_model),
105-
an_object_having_attributes(task_test),
106-
an_object_having_attributes(task_fixture)
107-
)
104+
an_object_having_attributes(task_model),
105+
an_object_having_attributes(task_test),
106+
an_object_having_attributes(task_fixture)
107+
)
108+
end
109+
end
110+
end
111+
end
112+
113+
describe 'annotate --routes' do
114+
let(:command) { 'bundle exec annotate --routes' }
115+
116+
let(:task_routes) do
117+
task_routes_diff = <<-DIFF
118+
+# == Route Map
119+
+#
120+
+# Prefix Verb URI Pattern Controller#Action
121+
+# tasks GET /tasks(.:format) tasks#index
122+
+# POST /tasks(.:format) tasks#create
123+
+# new_task GET /tasks/new(.:format) tasks#new
124+
+# edit_task GET /tasks/:id/edit(.:format) tasks#edit
125+
+# task GET /tasks/:id(.:format) tasks#show
126+
+# PATCH /tasks/:id(.:format) tasks#update
127+
+# PUT /tasks/:id(.:format) tasks#update
128+
+# DELETE /tasks/:id(.:format) tasks#destroy
129+
DIFF
130+
131+
default_routes_diff = <<-DIFF
132+
+# rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
133+
+# rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
134+
+# rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
135+
+# update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
136+
+# rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
137+
DIFF
138+
139+
path = 'config/routes.rb'
140+
{
141+
path: include(path),
142+
patch: include(task_routes_diff, default_routes_diff)
143+
}
144+
end
145+
146+
it 'annotate routes.rb' do
147+
Bundler.with_clean_env do
148+
Dir.chdir app_path do
149+
expect(git.diff.any?).to be_falsy
150+
151+
puts `#{command}`
152+
153+
expect(git.diff.entries).to include(
154+
an_object_having_attributes(task_routes)
155+
)
108156
end
109157
end
110158
end

0 commit comments

Comments
 (0)