Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom filenames to be passed for JS and CS
We're adding an admin interface to our application and want to use retain application.js & application.scss for the public interface. This will allow us to pass admin.js and admin.scss in as args so we can retain only loading the required components for each so the page load time is fast. There has been some added complexity in testing this as the #javascript_include_tag and #stylesheet_link_tag methods being passed a filename that isn't present in the assets directory will raise an error due to the file not being found when it's during attempted compilation. We have a few options here: 1. stub out the methods and return an empty string so there is no attempt to compile the file. In this situation we would just want to check that the methods receive the correct filename. 2. create the files dynamically prior to running the test, check the output on the rendered page and then delete the files after the test has run. 3. skip the test entirely. We've opted for option 1 as probably less complex and faster than option 2 and preferable to not testing at all. Unfortunately we've had to use "allow_any_instance_of" and "expect_any_instance_of" to stub the calls to check that the JS and CSS filenames are being passed into the #javascript_include_tag and #stylesheet_link_tag methods. These are implemeneted in the ActionView::Helpers::AssetTagHelper helper which is included in ActionView::Base which is particularly gnarly to attempt to stub a single instance of. While this isn't ideal, it's probably preferable to having to stub out a series of objects for what is essentially a very simple test which checks the correct filename is passed in.
- Loading branch information