publish_my_data 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
| @@ -51,8 +51,18 @@ module PublishMyData | |
| 51 51 | 
             
                  prefix = "dataset_data_#{@dataset.slug}_#{@dataset.modified.strftime("%Y%m%d")}"
         | 
| 52 52 | 
             
                  downloads = s3.buckets[PublishMyData.dataset_downloads_s3_bucket].objects.with_prefix(prefix).to_a
         | 
| 53 53 |  | 
| 54 | 
            -
                   | 
| 55 | 
            -
             | 
| 54 | 
            +
                  # filter the downloads to only include ones with a timestamp equal to or after the dataset modified date.
         | 
| 55 | 
            +
                  # (ones older than this are out of date)
         | 
| 56 | 
            +
                  current_downloads = downloads.select do |d|
         | 
| 57 | 
            +
                    date_portion = d.public_url.to_s.split("_").last.split('.').first  #between last underscore and first dot.
         | 
| 58 | 
            +
                    file_timestamp = DateTime.parse(date_portion)
         | 
| 59 | 
            +
                    file_timestamp >= @dataset.modified
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  # if we can't find a current download it's cos we haven't generated it yet since ds was modified
         | 
| 63 | 
            +
                  # ... and we should 404.
         | 
| 64 | 
            +
                  if current_downloads.any?
         | 
| 65 | 
            +
                    latest_download = current_downloads.last
         | 
| 56 66 | 
             
                    redirect_to latest_download.public_url.to_s
         | 
| 57 67 | 
             
                  else
         | 
| 58 68 | 
             
                    raise Tripod::Errors::ResourceNotFound
         | 
| @@ -204,7 +204,7 @@ module PublishMyData | |
| 204 204 |  | 
| 205 205 | 
             
                    let(:dataset) { FactoryGirl.create(:my_dataset) }
         | 
| 206 206 |  | 
| 207 | 
            -
                    context "when a download exists on s3" do
         | 
| 207 | 
            +
                    context "when a download exists on s3 for today" do
         | 
| 208 208 |  | 
| 209 209 | 
             
                      before do
         | 
| 210 210 | 
             
                        # make some downloads.
         | 
| @@ -229,12 +229,33 @@ module PublishMyData | |
| 229 229 |  | 
| 230 230 | 
             
                    end
         | 
| 231 231 |  | 
| 232 | 
            +
                    context "when a download exists on s3 for today, but before the modified date" do
         | 
| 233 | 
            +
             | 
| 234 | 
            +
                      before do
         | 
| 235 | 
            +
                        # make some downloads.
         | 
| 236 | 
            +
                        s3 = AWS::S3.new
         | 
| 237 | 
            +
                        bucket = s3.buckets[PublishMyData.dataset_downloads_s3_bucket]
         | 
| 238 | 
            +
             | 
| 239 | 
            +
                        @obj1 = bucket.objects.create("dataset_data_#{dataset.slug}_201007011159.nt.zip", 'data')
         | 
| 240 | 
            +
             | 
| 241 | 
            +
                        # make them public readable
         | 
| 242 | 
            +
                        [@obj1].each { |o| o.acl = :public_read }
         | 
| 243 | 
            +
                      end
         | 
| 244 | 
            +
             | 
| 245 | 
            +
                      it "should 404" do
         | 
| 246 | 
            +
                        get "dump", :id => dataset.slug, :use_route => :publish_my_data
         | 
| 247 | 
            +
                        response.should be_not_found
         | 
| 248 | 
            +
                      end
         | 
| 249 | 
            +
             | 
| 250 | 
            +
                    end
         | 
| 251 | 
            +
             | 
| 232 252 | 
             
                    context "when a download doesn't exist on s3" do
         | 
| 233 253 | 
             
                      it "should 404" do
         | 
| 234 254 | 
             
                        get "dump", :id => dataset.slug, :use_route => :publish_my_data
         | 
| 235 255 | 
             
                        response.should be_not_found
         | 
| 236 256 | 
             
                      end
         | 
| 237 257 | 
             
                    end
         | 
| 258 | 
            +
             | 
| 238 259 | 
             
                  end
         | 
| 239 260 |  | 
| 240 261 | 
             
                  context "when a dataset with that slug doesn't exist" do
         |