|
281 | 281 | expect(text_in(response.body, "h2")).to eql("Changed") |
282 | 282 | end |
283 | 283 | end |
| 284 | + |
| 285 | + context "in production" do |
| 286 | + before :each do |
| 287 | + set_rack_env :production |
| 288 | + end |
| 289 | + |
| 290 | + after :each do |
| 291 | + reset_rack_env |
| 292 | + end |
| 293 | + |
| 294 | + it "doesn't reload changed assets" do |
| 295 | + root = prepare_fixture(:assets) |
| 296 | + app = Hyperloop::Application.new(root) |
| 297 | + request = Rack::MockRequest.new(app) |
| 298 | + |
| 299 | + # On the first request, stylesheet should have `display: block` and not |
| 300 | + # `display: inline`. |
| 301 | + response = request.get("/assets/stylesheets/app.css") |
| 302 | + expect(response).to be_ok |
| 303 | + expect(response.body).to match(/display: ?block/) |
| 304 | + expect(response.body).not_to match(/display: ?inline/) |
| 305 | + |
| 306 | + # Load layout and change the title to "Changed" |
| 307 | + asset_path = File.join(root, "app", "assets", "stylesheets", "my-styles.scss") |
| 308 | + asset_data = File.read(asset_path) |
| 309 | + asset_data.sub!("display: block", "display: inline") |
| 310 | + File.write(asset_path, asset_data) |
| 311 | + |
| 312 | + # On the second request, stylesheet should still have `display: inline` |
| 313 | + # and not `display: block`. |
| 314 | + response = request.get("/assets/stylesheets/app.css") |
| 315 | + expect(response).to be_ok |
| 316 | + expect(response.body).to match(/display: ?block/) |
| 317 | + expect(response.body).not_to match(/display: ?inline/) |
| 318 | + end |
| 319 | + |
| 320 | + it "doesn't reload changed views" do |
| 321 | + root = prepare_fixture(:erb) |
| 322 | + app = Hyperloop::Application.new(root) |
| 323 | + request = Rack::MockRequest.new(app) |
| 324 | + |
| 325 | + # On the first request, <title> text should be "ERB" |
| 326 | + response = request.get("/") |
| 327 | + expect(response).to be_ok |
| 328 | + expect(text_in(response.body, "title")).to eql("ERB") |
| 329 | + |
| 330 | + # Load index.html.erb and change the title to "Changed" |
| 331 | + index_file_path = File.join(root, "app", "views", "index.html.erb") |
| 332 | + index_file_data = File.read(index_file_path) |
| 333 | + index_file_data.sub!(/<h2>[^<]*<\/h2>/, "<h2>Changed</h2>") |
| 334 | + File.write(index_file_path, index_file_data) |
| 335 | + |
| 336 | + # On the second request, <title> text should still be "ERB" |
| 337 | + response = request.get("/") |
| 338 | + expect(response).to be_ok |
| 339 | + expect(text_in(response.body, "title")).to eql("ERB") |
| 340 | + end |
| 341 | + end |
284 | 342 | end |
285 | 343 | end |
0 commit comments