spec/models/digital_asset_spec.rb in daengine-0.5.13 vs spec/models/digital_asset_spec.rb in daengine-0.6
- old
+ new
@@ -4,46 +4,47 @@
subject { FactoryGirl.build :digital_asset }
context '#fields' do
let(:defined_fields) {
- [:title, :changed_at, :sami_code, :product_ids, :summary,
- :published_at, :expires_at, :documents, :guid, :audiences]
+ [:title, :changed_at, :sami_code, :summary,
+ :published_at, :expires_at, :digital_asset_id, :audiences,
+ :path, :doc_changed_at,:content_type,:pages, :size, :mime_type,:subject,
+ :keywords, :author, :finra_path, :fund_codes]
}
it 'has all defined fields' do
defined_fields.each {|f| should respond_to(f)}
end
end
context '#validation' do
- required_fields = [:guid, :title, :changed_at, :published_at, :expires_at]
+ required_fields = [:digital_asset_id, :title, :changed_at, :published_at, :expires_at, :path]
required_fields.each do |f|
it "validates #{f} is required" do
should be_valid
subject.send("#{f}=", nil)
should be_invalid "should be invalid if #{f} is missing"
end
end
- it 'must have at least one document' do
- subject.documents.clear
- subject.should be_invalid
- end
it 'cannot have a past expiration date' do
subject.expires_at = 2.hours.ago
subject.should be_invalid
end
+ it "cannot have duplicate path" do
+ FactoryGirl.create :digital_asset, :path => "/some/path.pdf"
+ digital_asset = FactoryGirl.build :digital_asset, :path => "/some/path.pdf"
+ # p "errors = #{digital_asset.errors.inspect}"
+ digital_asset.should be_invalid
+ end
+ it "cannot have duplicate digital_asset_id" do
+ FactoryGirl.create :digital_asset, :digital_asset_id => "aaaa_kkkk_1234"
+ digital_asset = FactoryGirl.build :digital_asset, :digital_asset_id => "aaaa_kkkk_1234"
+ # p "errors = #{digital_asset.errors.inspect}"
+ digital_asset.should be_invalid
+ end
end
- context '#documents' do
- let(:manifest) { FactoryGirl.build :document, :path => '/foo/manifest/foo.doc'}
- it 'doesnt add manifest documents' do
- subject.documents << manifest
- subject.save.should be_false
- # DigitalAsset.find(subject.id).documents should have(1).document
- end
- end
-
context "purge!" do
before do
50.times { FactoryGirl.create :digital_asset }
FactoryGirl.create :digital_asset, :updated_at => 10.minutes.ago
end
@@ -57,48 +58,42 @@
context "#latest_doc_changed_at" do
before do
@one_day_ago = 1.day.ago
@asset = FactoryGirl.create :digital_asset,
:audiences => ['690'], :sami_code => 'F000000.BAR'
- @asset.documents << [DigitalAsset::Document.new(path: "/2/foo2/bar2.txt", doc_changed_at: @one_day_ago, content_type: '542')]
- @asset.documents << [DigitalAsset::Document.new(path: "/3/foo3/finra.txt", doc_changed_at: Time.now, content_type: '549')]
+ @asset.doc_changed_at = @one_day_ago
end
it 'returns latest doc changed at date which is not finra' do
result = @asset.latest_doc_changed_at
expect(result.to_i).to eq @one_day_ago.to_i
end
- it 'returns json with latest doc changed at date' do
- result = @asset.as_json
- expect(result[:latest_doc_changed_at]).to eq @one_day_ago.strftime('%Y-%m-%d %H:%M:%S')
- end
-
end
context '#finders' do
before do
@asset = FactoryGirl.create :digital_asset,
:audiences => ['690'], :sami_code => 'F000000.BAR'
FactoryGirl.create :digital_asset,
:sami_code => 'MEH12345.000', :updated_at => 1.hour.ago
end
- it 'has a finder by product_id' do
- DigitalAsset.should respond_to(:product_in)
- DigitalAsset.product_in(['690']).should have(2).digital_asset
+ it 'has a finder by fund code' do
+ DigitalAsset.should respond_to(:fund_in)
+ DigitalAsset.fund_in(['00190']).should have(2).digital_asset
end
it 'has a finder by sami_code' do
DigitalAsset.should respond_to(:sami_is)
DigitalAsset.sami_is('F000000.BAR').should have(1).digital_asset
end
it 'has a finder by the embedded doc path' do
DigitalAsset.should respond_to(:path_is)
- DigitalAsset.path_is(@asset.documents.first.path).should have(1).digital_asset
+ DigitalAsset.path_is(@asset.path).should have(1).digital_asset
end
it 'has a type finder for the documents' do
DigitalAsset.should respond_to(:doctype_in)
- DigitalAsset.doctype_in(['666']).should have(2).digital_asset
+ DigitalAsset.doctype_in(['fact_sheet']).should have(2).digital_asset
end
it 'has a finder for stale documents' do
DigitalAsset.should respond_to(:stale)
DigitalAsset.stale.should have(1).item
end