Files
grecia/spec/models/document_spec.rb
Javi Martín 4f232c3a25 Use the file_fixture helper in tests
This way we don't have to write `"spec/fixtures/files"` every time.

Note this method isn't included in factories. We could include it like
so:

```
FactoryBot::SyntaxRunner.class_eval do
  include ActiveSupport::Testing::FileFixtures
  self.file_fixture_path = RSpec.configuration.file_fixture_path
end
```

However, I'm not sure about the possible side effects, and since we only
use attachments in a few factories, there isn't much gain in applying
the monkey-patch.
2022-02-23 18:43:48 +01:00

30 lines
785 B
Ruby

require "rails_helper"
describe Document do
it_behaves_like "document validations", "budget_investment_document"
it_behaves_like "document validations", "proposal_document"
it "stores attachments with Active Storage" do
document = create(:document, attachment: File.new(file_fixture("clippy.pdf")))
expect(document.attachment).to be_attached
expect(document.attachment.filename).to eq "clippy.pdf"
end
context "scopes" do
describe "#admin" do
it "returns admin documents" do
admin_document = create(:document, :admin)
expect(Document.admin).to eq [admin_document]
end
it "does not return user documents" do
create(:document, admin: false)
expect(Document.admin).to be_empty
end
end
end
end