cloudxls-rails 0.4.2 → 0.4.3
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.
- data/lib/cloudxls-rails/handlers/csv.rb +1 -1
 - data/lib/cloudxls-rails/handlers/xls.rb +12 -2
 - data/lib/cloudxls-rails/handlers/xlsx.rb +3 -2
 - data/lib/cloudxls-rails/version.rb +1 -1
 - data/spec/integration_spec.rb +31 -1
 - data/spec/test_app/app/controllers/posts_controller.rb +11 -2
 - data/spec/test_app/config/routes.rb +1 -0
 - data/spec/test_app/db/schema.rb +28 -0
 - metadata +4 -2
 
| 
         @@ -35,7 +35,7 @@ ActionController::Renderers.add :csv do |scope, options| 
     | 
|
| 
       35 
35 
     | 
    
         
             
              filename = options.fetch(:filename, "data-#{DateTime.now.to_s}.csv")
         
     | 
| 
       36 
36 
     | 
    
         
             
              columns  = options[:columns]
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
              if options[:stream] 
     | 
| 
      
 38 
     | 
    
         
            +
              if options[:stream]
         
     | 
| 
       39 
39 
     | 
    
         
             
                CloudXLSRails::CSVResponder.stream!(self, scope, options)
         
     | 
| 
       40 
40 
     | 
    
         
             
              else # no stream:
         
     | 
| 
       41 
41 
     | 
    
         
             
                data = CloudXLS::CSVWriter.text(scope, {:columns => columns})
         
     | 
| 
         @@ -29,10 +29,20 @@ end 
     | 
|
| 
       29 
29 
     | 
    
         
             
            # For respond_to default
         
     | 
| 
       30 
30 
     | 
    
         
             
            class ActionController::Responder
         
     | 
| 
       31 
31 
     | 
    
         
             
              def to_xls
         
     | 
| 
       32 
     | 
    
         
            -
                 
     | 
| 
      
 32 
     | 
    
         
            +
                stream = options.delete(:stream) || false
         
     | 
| 
      
 33 
     | 
    
         
            +
                if stream # either string or boolean
         
     | 
| 
       33 
34 
     | 
    
         
             
                  options[:data] ||= {}
         
     | 
| 
       34 
     | 
    
         
            -
                  options[:data][:url] ||=  
     | 
| 
      
 35 
     | 
    
         
            +
                  options[:data][:url] ||= cloudxls_stream_url(stream, 'xls')
         
     | 
| 
       35 
36 
     | 
    
         
             
                end
         
     | 
| 
       36 
37 
     | 
    
         
             
                CloudXLSRails::XLSResponder.redirect!(controller, resources.last, options)
         
     | 
| 
       37 
38 
     | 
    
         
             
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            protected
         
     | 
| 
      
 41 
     | 
    
         
            +
              def cloudxls_stream_url(stream, extension = 'xls')
         
     | 
| 
      
 42 
     | 
    
         
            +
                if stream == true
         
     | 
| 
      
 43 
     | 
    
         
            +
                  controller.request.url.gsub(/#{extension}\Z/, "csv")
         
     | 
| 
      
 44 
     | 
    
         
            +
                else
         
     | 
| 
      
 45 
     | 
    
         
            +
                  stream.to_s
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
       38 
48 
     | 
    
         
             
            end
         
     | 
| 
         @@ -30,9 +30,10 @@ end 
     | 
|
| 
       30 
30 
     | 
    
         
             
            # For respond_to default
         
     | 
| 
       31 
31 
     | 
    
         
             
            class ActionController::Responder
         
     | 
| 
       32 
32 
     | 
    
         
             
              def to_xlsx
         
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 33 
     | 
    
         
            +
                stream = options.delete(:stream) || false
         
     | 
| 
      
 34 
     | 
    
         
            +
                if stream # either string or boolean
         
     | 
| 
       34 
35 
     | 
    
         
             
                  options[:data] ||= {}
         
     | 
| 
       35 
     | 
    
         
            -
                  options[:data][:url] ||=  
     | 
| 
      
 36 
     | 
    
         
            +
                  options[:data][:url] ||= cloudxls_stream_url(stream, 'xlsx')
         
     | 
| 
       36 
37 
     | 
    
         
             
                end
         
     | 
| 
       37 
38 
     | 
    
         
             
                CloudXLSRails::XLSXResponder.redirect!(controller, resources.last, options)
         
     | 
| 
       38 
39 
     | 
    
         
             
              end
         
     | 
    
        data/spec/integration_spec.rb
    CHANGED
    
    | 
         @@ -58,7 +58,7 @@ describe 'Request', :type => :request do 
     | 
|
| 
       58 
58 
     | 
    
         | 
| 
       59 
59 
     | 
    
         
             
                it "/posts/stream.xls has a working csv export" do
         
     | 
| 
       60 
60 
     | 
    
         
             
                  CloudXLS.should_receive(:xpipe) { |options|
         
     | 
| 
       61 
     | 
    
         
            -
                    !options[:data][:url]. 
     | 
| 
      
 61 
     | 
    
         
            +
                    !options[:data][:url].ends_with?("posts/stream.csv") &&
         
     | 
| 
       62 
62 
     | 
    
         
             
                      options.keys.length == 1
         
     | 
| 
       63 
63 
     | 
    
         
             
                  }.and_return(OpenStruct.new(:url => "/successful_redirect"))
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
         @@ -66,4 +66,34 @@ describe 'Request', :type => :request do 
     | 
|
| 
       66 
66 
     | 
    
         
             
                  page.should have_content("OK")
         
     | 
| 
       67 
67 
     | 
    
         
             
                end
         
     | 
| 
       68 
68 
     | 
    
         
             
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              describe "/posts/stream_with_custom_url" do
         
     | 
| 
      
 71 
     | 
    
         
            +
                it "/posts/stream_with_custom_url.csv should xpipe with csv url" do
         
     | 
| 
      
 72 
     | 
    
         
            +
                  visit '/posts/stream_with_custom_url.csv'
         
     | 
| 
      
 73 
     | 
    
         
            +
                  page.should have_content [
         
     | 
| 
      
 74 
     | 
    
         
            +
                    "Title,Visits,Conversion Rate,Published On,Published,Expired At",
         
     | 
| 
      
 75 
     | 
    
         
            +
                    "hello world,12032,0.24,2013-12-24,false,2013-12-25T12:30:30.000+0000"
         
     | 
| 
      
 76 
     | 
    
         
            +
                  ].join("\n")
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                it "/posts/stream_with_custom_url.xls will redirect to custom url" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                  CloudXLS.should_receive(:xpipe) { |options|
         
     | 
| 
      
 81 
     | 
    
         
            +
                    !options[:data][:url].ends_with?("successful_redirect") &&
         
     | 
| 
      
 82 
     | 
    
         
            +
                      options.keys.length == 1
         
     | 
| 
      
 83 
     | 
    
         
            +
                  }.and_return(OpenStruct.new(:url => "/successful_redirect"))
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  visit '/posts/stream_with_custom_url.xls'
         
     | 
| 
      
 86 
     | 
    
         
            +
                  page.should have_content("OK")
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                it "/posts/stream_with_custom_url.xlsx will redirect to custom url" do
         
     | 
| 
      
 90 
     | 
    
         
            +
                  CloudXLS.should_receive(:xpipe) { |options|
         
     | 
| 
      
 91 
     | 
    
         
            +
                    !options[:data][:url].ends_with?("successful_redirect") &&
         
     | 
| 
      
 92 
     | 
    
         
            +
                      options.keys.length == 1
         
     | 
| 
      
 93 
     | 
    
         
            +
                  }.and_return(OpenStruct.new(:url => "/successful_redirect"))
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  visit '/posts/stream_with_custom_url.xlsx'
         
     | 
| 
      
 96 
     | 
    
         
            +
                  page.should have_content("OK")
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
              end
         
     | 
| 
       69 
99 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,11 +2,20 @@ class PostsController < ApplicationController 
     | 
|
| 
       2 
2 
     | 
    
         
             
              respond_to :csv, :xls, :xlsx, :html
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
              def index
         
     | 
| 
       5 
     | 
    
         
            -
                respond_with(Post.all, 
     | 
| 
      
 5 
     | 
    
         
            +
                respond_with(Post.all,
         
     | 
| 
      
 6 
     | 
    
         
            +
                  :columns => export_attributes)
         
     | 
| 
       6 
7 
     | 
    
         
             
              end
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
              def stream
         
     | 
| 
       9 
     | 
    
         
            -
                respond_with(Post.all, 
     | 
| 
      
 10 
     | 
    
         
            +
                respond_with(Post.all,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  :stream => true,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :columns => export_attributes)
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def stream_with_custom_url
         
     | 
| 
      
 16 
     | 
    
         
            +
                respond_with(Post.all,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :stream => "/successful_redirect",
         
     | 
| 
      
 18 
     | 
    
         
            +
                  :columns => export_attributes)
         
     | 
| 
       10 
19 
     | 
    
         
             
              end
         
     | 
| 
       11 
20 
     | 
    
         | 
| 
       12 
21 
     | 
    
         
             
              # Used for stub/mocking a redirect request
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: UTF-8
         
     | 
| 
      
 2 
     | 
    
         
            +
            # This file is auto-generated from the current state of the database. Instead
         
     | 
| 
      
 3 
     | 
    
         
            +
            # of editing this file, please use the migrations feature of Active Record to
         
     | 
| 
      
 4 
     | 
    
         
            +
            # incrementally modify your database, and then regenerate this schema definition.
         
     | 
| 
      
 5 
     | 
    
         
            +
            #
         
     | 
| 
      
 6 
     | 
    
         
            +
            # Note that this schema.rb definition is the authoritative source for your
         
     | 
| 
      
 7 
     | 
    
         
            +
            # database schema. If you need to create the application database on another
         
     | 
| 
      
 8 
     | 
    
         
            +
            # system, you should be using db:schema:load, not running all the migrations
         
     | 
| 
      
 9 
     | 
    
         
            +
            # from scratch. The latter is a flawed and unsustainable approach (the more migrations
         
     | 
| 
      
 10 
     | 
    
         
            +
            # you'll amass, the slower it'll run and the greater likelihood for issues).
         
     | 
| 
      
 11 
     | 
    
         
            +
            #
         
     | 
| 
      
 12 
     | 
    
         
            +
            # It's strongly recommended that you check this file into your version control system.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            ActiveRecord::Schema.define(version: 20120717192452) do
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              create_table "posts", force: true do |t|
         
     | 
| 
      
 17 
     | 
    
         
            +
                t.string   "title"
         
     | 
| 
      
 18 
     | 
    
         
            +
                t.integer  "visits"
         
     | 
| 
      
 19 
     | 
    
         
            +
                t.float    "conversion_rate"
         
     | 
| 
      
 20 
     | 
    
         
            +
                t.date     "published_on"
         
     | 
| 
      
 21 
     | 
    
         
            +
                t.datetime "expired_at"
         
     | 
| 
      
 22 
     | 
    
         
            +
                t.boolean  "published"
         
     | 
| 
      
 23 
     | 
    
         
            +
                t.datetime "unix_timestamp"
         
     | 
| 
      
 24 
     | 
    
         
            +
                t.datetime "created_at"
         
     | 
| 
      
 25 
     | 
    
         
            +
                t.datetime "updated_at"
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: cloudxls-rails
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.4. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013-11- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-11-21 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: cloudxls
         
     | 
| 
         @@ -162,6 +162,7 @@ files: 
     | 
|
| 
       162 
162 
     | 
    
         
             
            - spec/test_app/config/locales/en.yml
         
     | 
| 
       163 
163 
     | 
    
         
             
            - spec/test_app/config/routes.rb
         
     | 
| 
       164 
164 
     | 
    
         
             
            - spec/test_app/db/migrate/20120717192452_create_posts.rb
         
     | 
| 
      
 165 
     | 
    
         
            +
            - spec/test_app/db/schema.rb
         
     | 
| 
       165 
166 
     | 
    
         
             
            - spec/test_app/lib/assets/.gitkeep
         
     | 
| 
       166 
167 
     | 
    
         
             
            - spec/test_app/log/.gitkeep
         
     | 
| 
       167 
168 
     | 
    
         
             
            - spec/test_app/public/404.html
         
     | 
| 
         @@ -233,6 +234,7 @@ test_files: 
     | 
|
| 
       233 
234 
     | 
    
         
             
            - spec/test_app/config/locales/en.yml
         
     | 
| 
       234 
235 
     | 
    
         
             
            - spec/test_app/config/routes.rb
         
     | 
| 
       235 
236 
     | 
    
         
             
            - spec/test_app/db/migrate/20120717192452_create_posts.rb
         
     | 
| 
      
 237 
     | 
    
         
            +
            - spec/test_app/db/schema.rb
         
     | 
| 
       236 
238 
     | 
    
         
             
            - spec/test_app/lib/assets/.gitkeep
         
     | 
| 
       237 
239 
     | 
    
         
             
            - spec/test_app/log/.gitkeep
         
     | 
| 
       238 
240 
     | 
    
         
             
            - spec/test_app/public/404.html
         
     |