Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ActiveSupport::Testing::FileFixtures. #18658

Merged
merged 1 commit into from Jan 28, 2015
Merged

Conversation

senny
Copy link
Member

@senny senny commented Jan 23, 2015

It's a thin layer to provide easy access to sample files throughout
test-cases. This adds the directory test/fixtures/files to newly
generated applications.

This is something that came up in a discussion with @dhh

Most of our applications have helpers to access some kind of sample files. Possible use-cases are:

  • Test file uploads
  • Sample output to compare generated documents (.csv, .docx, .pdf, ...)
  • content used in test-cases like xml snippets.
  • ...

@senny
Copy link
Member Author

senny commented Jan 23, 2015

@carlosantoniodasilva @rafaelfranca @dhh interested to hear your thoughts.

The method names feel a bit awkward to me but it's the best I could come up with.

@senny senny added this to the 5.0.0 milestone Jan 23, 2015
@arthurnn
Copy link
Member

🆒

@vipulnsward
Copy link
Member

Nice. @senny it would be awesome if this could be extended to support passing a file in controller requests in tests. Thoughts?

@rafaelfranca
Copy link
Member

Seems good to me.

class_attribute :file_fixture_directory
end

# return the contents of the fixture file named +fixture_name+.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit-picky thing but it should be "Returns" here, no ?

@@ -21,6 +21,7 @@
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
self.fixture_path = "#{Rails.root}/test/fixtures/"
self.file_fixture_directory = Rails.root + "test/fixtures/files"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: fixture_path + "files"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@carlosantoniodasilva
Copy link
Member

I wonder if we should touch fixture_file_upload to make use of this new files directory rather than the normal fixtures_path in this case?

Other than that it seems good to me, good to have something simple builtin to help with that.

@senny senny force-pushed the file_fixtures branch 2 times, most recently from 5ae37f7 to 06c7fff Compare Jan 28, 2015
@senny
Copy link
Member Author

senny commented Jan 28, 2015

I changed the configuration option to file_fixture_path and the methods to file_fixture and file_fixture_content.

@carlosantoniodasilva what do you think?

@carlosantoniodasilva
Copy link
Member

Cool, I like it better 👍, do you prefer like this?

Would you think that leaving the "read" logic for the developers wouldn't be fine? I mean, we could use file_fixture('zomg.txt').read directly on the tests, and only introduce this helper method with the config.

@senny
Copy link
Member Author

senny commented Jan 28, 2015

@carlosantoniodasilva 👍 I think we can get rid of _content and delegate .read to the user. I'll try to cover it in the documentation. Once that base-layer is merged we can start talking about fixture_file_upload.

@carlosantoniodasilva
Copy link
Member

Alright, great 👍 ❤️

@senny
Copy link
Member Author

senny commented Jan 28, 2015

@carlosantoniodasilva mind a final 👀?

@@ -1,3 +1,11 @@
* Add `file_fixture` to `ActiveSupport::TestCase`.
They provide a simple mechanism to access sample files in your test cases.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/they provide/it provides ?

@carlosantoniodasilva
Copy link
Member

💚💛❤️💙💜

It's a thin layer to provide easy access to sample files throughout
test-cases. This adds the directory `test/fixtures/files` to newly
generated applications.
senny added a commit that referenced this pull request Jan 28, 2015
Add `ActiveSupport::Testing::FileFixtures`.
@senny senny merged commit 58047eb into rails:master Jan 28, 2015
@senny senny deleted the file_fixtures branch Jan 28, 2015
@senny
Copy link
Member Author

senny commented Jan 28, 2015

@carlosantoniodasilva thanks man!!! 💛

@carlosantoniodasilva
Copy link
Member

thank you 👍 💙

@rafaelfranca rafaelfranca modified the milestones: 5.0.0 [temp], 5.0.0 Dec 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants