From b90837e59d344b44b59bd91861904cbeb044044f Mon Sep 17 00:00:00 2001 From: basnal Date: Fri, 11 Jul 2014 10:46:42 +0530 Subject: [PATCH] Code was re organised #11 --- .gitignore | 1 + Gemfile | 14 +- Gemfile.lock | 9 ++ app/assets/javascripts/spreadsheets.js.coffee | 6 + app/assets/stylesheets/bootstrap_config.scss | 1 + app/assets/stylesheets/spreadsheets.css.scss | 3 + app/controllers/application_controller.rb | 1 - app/controllers/callbacks_controller.rb | 6 +- app/controllers/spreadsheets_controller.rb | 57 +++++++++ app/helpers/spreadsheets_helper.rb | 2 + app/models/spreadsheet.rb | 28 ++++ app/models/user.rb | 8 ++ app/views/layouts/application.html.haml | 48 +++---- app/views/spreadsheets/edit.html.haml | 1 + app/views/spreadsheets/index.html.haml | 31 +++++ app/views/spreadsheets/new.html.haml | 7 + config/application.rb | 1 + config/initializers/google_oauth.rb | 7 +- config/routes.rb | 11 +- lib/google_spreadsheets.rb | 46 +++++++ spec/controllers/google_auth_response.json | 12 ++ spec/controllers/host_response.json | 121 ++++++++++++++++++ .../spreadsheets_controller_spec.rb | 29 +++++ spec/factories/spreadsheets.rb | 6 + spec/helpers/spreadsheets_helper_spec.rb | 15 +++ spec/models/spreadsheet_spec.rb | 5 + spec/spec_helper.rb | 2 +- 27 files changed, 434 insertions(+), 44 deletions(-) create mode 100644 app/assets/javascripts/spreadsheets.js.coffee create mode 100644 app/assets/stylesheets/spreadsheets.css.scss create mode 100644 app/controllers/spreadsheets_controller.rb create mode 100644 app/helpers/spreadsheets_helper.rb create mode 100644 app/models/spreadsheet.rb create mode 100644 app/views/spreadsheets/edit.html.haml create mode 100644 app/views/spreadsheets/index.html.haml create mode 100644 app/views/spreadsheets/new.html.haml create mode 100644 lib/google_spreadsheets.rb create mode 100644 spec/controllers/google_auth_response.json create mode 100644 spec/controllers/host_response.json create mode 100644 spec/controllers/spreadsheets_controller_spec.rb create mode 100644 spec/factories/spreadsheets.rb create mode 100644 spec/helpers/spreadsheets_helper_spec.rb create mode 100644 spec/models/spreadsheet_spec.rb diff --git a/.gitignore b/.gitignore index b397243..72dcb25 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ build/ /log/ /tmp *.log +test.html.haml diff --git a/Gemfile b/Gemfile index ad977a6..e6540b2 100644 --- a/Gemfile +++ b/Gemfile @@ -70,16 +70,20 @@ gem 'bootstrap-sass' # The following gems for testing purpose in development and testing environment group :development, :test do -# Rspec is used to write the test cases + # Rspec is used to write the test cases gem 'rspec-rails' -# Use factory girl to pass random data for test cases + # Use factory girl to pass random data for test cases gem 'factory_girl_rails' -# Use faker to generate fake strings and data + # Use faker to generate fake strings and data gem 'faker' -# Use to clean database after executing a test case + # Use to clean database after executing a test case gem 'database_cleaner' -# Use to track how much code has been tested + # Use to track how much code has been tested gem 'simplecov' + # Webmock to stub http requests + gem 'webmock' + # VCR to record the responses from web and replay them when needed + gem 'vcr' end gem 'simple_form' diff --git a/Gemfile.lock b/Gemfile.lock index e0d401c..16efa74 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,6 +58,8 @@ GEM execjs coffee-script-source (1.7.0) connection_pool (2.0.0) + crack (0.4.2) + safe_yaml (~> 1.0.0) database_cleaner (1.3.0) devise (3.2.4) bcrypt (~> 3.0) @@ -210,6 +212,7 @@ GEM rspec-mocks (~> 3.0.0) rspec-support (~> 3.0.0) rspec-support (3.0.2) + safe_yaml (1.0.3) sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -270,8 +273,12 @@ GEM execjs (>= 0.3.0) json (>= 1.8.0) uuidtools (2.1.4) + vcr (2.9.2) warden (1.2.3) rack (>= 1.0) + webmock (1.18.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) PLATFORMS ruby @@ -307,3 +314,5 @@ DEPENDENCIES therubyracer turbolinks uglifier (>= 1.3.0) + vcr + webmock diff --git a/app/assets/javascripts/spreadsheets.js.coffee b/app/assets/javascripts/spreadsheets.js.coffee new file mode 100644 index 0000000..bb6bec6 --- /dev/null +++ b/app/assets/javascripts/spreadsheets.js.coffee @@ -0,0 +1,6 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ +xyz = -> + alert "welcome" + return \ No newline at end of file diff --git a/app/assets/stylesheets/bootstrap_config.scss b/app/assets/stylesheets/bootstrap_config.scss index c2c0a35..97dbd4a 100644 --- a/app/assets/stylesheets/bootstrap_config.scss +++ b/app/assets/stylesheets/bootstrap_config.scss @@ -1,4 +1,5 @@ @import "bootstrap"; + body { padding-top: 80px; diff --git a/app/assets/stylesheets/spreadsheets.css.scss b/app/assets/stylesheets/spreadsheets.css.scss new file mode 100644 index 0000000..2f69a6e --- /dev/null +++ b/app/assets/stylesheets/spreadsheets.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the spreadsheets controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2ec37e2..d83690e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,5 +2,4 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - end diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb index 73aaea1..ee64347 100644 --- a/app/controllers/callbacks_controller.rb +++ b/app/controllers/callbacks_controller.rb @@ -54,9 +54,9 @@ def setSheet end def insertEmailInDatabase(tkn) - @tkn = tkn - session = GoogleDrive.login_with_oauth(@tkn["access_token"]) - @ws = session.spreadsheet_by_key(@tkn['spreadsheet_id']).worksheets[0] + @tkn = tkn + session = GoogleDrive.login_with_oauth(@tkn["access_token"]) + @ws = session.spreadsheet_by_key(@tkn['spreadsheet_id']).worksheets[0] rowcount = @ws.rows.count diff --git a/app/controllers/spreadsheets_controller.rb b/app/controllers/spreadsheets_controller.rb new file mode 100644 index 0000000..8bf26d1 --- /dev/null +++ b/app/controllers/spreadsheets_controller.rb @@ -0,0 +1,57 @@ +class SpreadsheetsController < ApplicationController + include GoogleSpreadsheets + + def index + @spreadsheets = Spreadsheet.all.to_a + end + + def new + @req = params +=begin + if params[:access_token] + spreadsheet = Spreadsheet.where(access_token: params['access_token'])[0] + else + spreadsheet = Spreadsheet.new + spreadsheet.add_tokens(request.env['omniauth.auth'].fetch('credentials')) + end + + if spreadsheet.save + # Spreadsheets from google + @spreadsheets = get_spreadsheets(spreadsheet) + @token = spreadsheet.access_token + @msg = 'work' + else + @msg = 'no work' + # Handle if data does not get saved + end +=end + end + + def edit + token = spreadsheet_params['token'] + spreadsheet = Spreadsheet.where(access_token: token)[0] + spreadsheet.add_spreadsheet_credentials(spreadsheet_params) + #binding.pry + spreadsheet.save + + @spreadsheets = Spreadsheet.all.to_a + + render action: 'index' + end + + def update + spreadsheet = Spreadsheet.find(params['id']) + @worksheet = get_worksheets(spreadsheet) + User.add_users_from_worksheet(@worksheet) + redirect_to users_path + end + + def destroy + Spreadsheet.find(params['id']).delete + redirect_to spreadsheets_path + end + + def spreadsheet_params + params.permit(:title, :id, :token) + end +end diff --git a/app/helpers/spreadsheets_helper.rb b/app/helpers/spreadsheets_helper.rb new file mode 100644 index 0000000..4d8051e --- /dev/null +++ b/app/helpers/spreadsheets_helper.rb @@ -0,0 +1,2 @@ +module SpreadsheetsHelper +end diff --git a/app/models/spreadsheet.rb b/app/models/spreadsheet.rb new file mode 100644 index 0000000..e8fed63 --- /dev/null +++ b/app/models/spreadsheet.rb @@ -0,0 +1,28 @@ +class Spreadsheet + include Mongoid::Document + + field :spreadsheet_id, type: String + field :spreadsheet_title, type: String + field :refresh_token, type: String + field :expires_at, type: Time + field :access_token, type: String + + validates :access_token, uniqueness: true + + def add_tokens(tokens = {}) + self['access_token'] = tokens.fetch('token') + self['refresh_token'] = tokens.fetch('refresh_token') + self['expires_at'] = tokens.fetch('expires_at') + end + + def add_spreadsheet_credentials(credentials = {}) + #binding.pry + self['spreadsheet_id'] = credentials['id'] + self['spreadsheet_title'] = credentials['title'] + end + + def access_token + self['access_token'] + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 11bfd53..297dcb9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,4 +14,12 @@ class User belongs_to :newsletter, counter_cache: :users_count + def self.add_users_from_worksheet(worksheet, column = 1) + worksheet.rows.count.times do |i| + User.create(email_id: worksheet[i + 1, column], + is_subscribed: true, + joined_on: Date.today, + source: 'Google Spreadsheet') + end + end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 051cbd9..d9b2ace 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -12,35 +12,35 @@ .navbar-brand %h4 LightAir - %ul.nav.navbar-nav - %li.active - %a{href: "#{home_index_path}"} - %h4 Home - %li - %a{href: "#"} - %h4 Newsletters - %li.dropdown - %a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"} - %h4 - Add Users - %span.caret - %ul.dropdown-menu{role: "menu", "aria-labelledby" => "dropdownMenu1" } - %li - %a{role: "menuitem", tabindex: "-1", href: "#{new_user_path}"}Manually - %li - %a{role: "menuitem", tabindex: "-2", href: "#{callback_index_path}"}Google Spreadsheets - %li - %a{role: "menuitem", tabindex: "-1", href: "#{linkedin_path}"}Linkedin Connections - %li - %a{href: "#{users_path}"} - %h4 All Users + %div.nav-collapse + %ul.nav.navbar-nav + %li.active + %a{href: "#{home_index_path}"} + %h4 Home + %li + %a{href: "#"} + %h4 Newsletters + %li + %a{href: "#{users_path}"} + %h4 Show Users + %li.dropdown + %a.dropdown-toggle{"data-toggle" => "dropdown"} + %h4 + Add Users + %span.caret + %ul.dropdown-menu{role: "menu", "aria-labelledby" => "dropdownMenu1" } + %li + %a{role: "menuitem", tabindex: "-1", href: "#{new_user_path}"}Add Manually + %li + %a{role: "menuitem", tabindex: "-2", href: "#{spreadsheets_path}"}Google Spreadsheets %ul.nav.navbar-nav.navbar-right %li.active %a{href: "#"} - Subscriber count : - =User.count + %h4 + Subscriber count : + =User.count %div.container %div.row %div.col-sm-9= yield diff --git a/app/views/spreadsheets/edit.html.haml b/app/views/spreadsheets/edit.html.haml new file mode 100644 index 0000000..ee1ae52 --- /dev/null +++ b/app/views/spreadsheets/edit.html.haml @@ -0,0 +1 @@ +=debug @sp \ No newline at end of file diff --git a/app/views/spreadsheets/index.html.haml b/app/views/spreadsheets/index.html.haml new file mode 100644 index 0000000..ec9f293 --- /dev/null +++ b/app/views/spreadsheets/index.html.haml @@ -0,0 +1,31 @@ +%h4 + =link_to 'Add New Spreadsheet', 'auth/google/' + +%table.table.table-striped + %tr.info + %td + %strong # + %td + %strong + Spreadsheets ( + =Spreadsheet.count + ) + %td + %strong Operations + - i = 0 + - @spreadsheets.each do |ss| + %tr + %td + = i = i + 1 + %td + - if ss['spreadsheet_title'] + =ss['spreadsheet_title'] + -else + =link_to 'Spreadsheet not initialised', new_spreadsheet_path(access_token: ss['access_token']) + %td + =link_to 'Delete', spreadsheet_path(ss), method: :delete + -if ss['spreadsheet_title'] + | + =link_to 'Update', spreadsheet_path(ss), method: :patch + + diff --git a/app/views/spreadsheets/new.html.haml b/app/views/spreadsheets/new.html.haml new file mode 100644 index 0000000..4a3f606 --- /dev/null +++ b/app/views/spreadsheets/new.html.haml @@ -0,0 +1,7 @@ +=@req +%br +-#count = @spreadsheets.count +=#count +-#count.times do |i| + =#link_to @spreadsheets[i]['title'], edit_spreadsheet_path(@spreadsheets[i]['id'], title: @spreadsheets[i]['title'], token: @token) if @spreadsheets[i]['mimeType'].include?('spreadsheet') + %br \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 6e89af7..13fe384 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,6 +16,7 @@ module Lightair class Application < Rails::Application config.assets.precompile += %w(*.png, *.jpg, *.jpeg, *.gif) + config.autoload_paths += Dir["#{config.root}/lib/**/"] # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/config/initializers/google_oauth.rb b/config/initializers/google_oauth.rb index 12de4e8..69265b6 100644 --- a/config/initializers/google_oauth.rb +++ b/config/initializers/google_oauth.rb @@ -1,11 +1,10 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :google_oauth2, ENV['GOOGLE_ID'], ENV['GOOGLE_KEY'], { - name: "google", + name: 'google', scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds', prompt: 'consent', - access_type: "offline", + access_type: 'offline', + #redirect_uri: 'http://localhost:8080/auth/google/spreadsheets' } - - #provider :linkedin, '75cmlzl0cpmwa2', 'I5y0aRBkfpgMmTqp', redirect_uri: 'http://localhost:8080/auth/linkedin/callback', scope:'r_emailaddress r_network r_contactinfo rw_company_admin rw_nus rw_groups w_messages r_basicprofile r_fullprofile' end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3c7b591..8f07095 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,17 +1,16 @@ Rails.application.routes.draw do - +=begin get '/home/sheets', to: 'home#add_from_google', as: 'add_from_google' get '/auth/:provider/callback', to: 'callbacks#omniauth' get '/linkedin', to: 'callbacks#linkedin', as: 'linkedin' get '/callbacks/sheet/:id', to: 'callbacks#setSheet', as: 'set_sheet' get '/callbacks/index', to: 'callbacks#index', as: 'callback_index' get '/callbacks/update/:id', to: 'callbacks#update', as: 'callback_update' - - resources :users - resources :newsletters - resources :home +=end + get '/auth/:provider/callback', to: 'spreadsheets#new' + resources :users, :newsletters, :home, :spreadsheets - root :to => "home#index" + root :to => 'home#index' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/lib/google_spreadsheets.rb b/lib/google_spreadsheets.rb new file mode 100644 index 0000000..880fb04 --- /dev/null +++ b/lib/google_spreadsheets.rb @@ -0,0 +1,46 @@ +module GoogleSpreadsheets + def get_spreadsheets(spreadsheet) + #binding.pry + if Time.now > spreadsheet['expires_at'] + spreadsheet = refresh_token spreadsheet + end + + client = Google::APIClient.new + client.authorization.access_token = spreadsheet.access_token + drive = client.discovered_api('drive', 'v2') + + wks = client.execute( + api_method: drive.files.list, + parameters: {}, + headers: {'Content-Type' => 'application/json'} + ) + (JSON.parse(wks.data.to_json))['items'] + end + + def get_worksheets(spreadsheet, i = 0) + if Time.now > spreadsheet['expires_at'] + spreadsheet = refresh_token spreadsheet + end + + session = GoogleDrive.login_with_oauth(spreadsheet['access_token']) + session.spreadsheet_by_key(spreadsheet['spreadsheet_id']).worksheets[i] + end + + def refresh_token(spreadsheet) + data = { + client_id: ENV['GOOGLE_ID'], + client_secret: ENV['GOOGLE_KEY'], + refresh_token: spreadsheet['refresh_token'], + grant_type: 'refresh_token' + } + re = ActiveSupport::JSON.decode(RestClient.post 'https://accounts.google.com/o/oauth2/token', data) + + #sheets = Token.where(spreadsheet_id: spreadsheet['spreadsheet_id'])[0] + spreadsheet['access_token'] = re['access_token'] + spreadsheet['expires_at'] = (Time.now + re['expires_in'].second).localtime + #binding.pry + spreadsheet.save + + spreadsheet + end +end \ No newline at end of file diff --git a/spec/controllers/google_auth_response.json b/spec/controllers/google_auth_response.json new file mode 100644 index 0000000..8473da2 --- /dev/null +++ b/spec/controllers/google_auth_response.json @@ -0,0 +1,12 @@ +HTTP/1.1 302 Found +Content-Length: 537 +Location: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367225507767-119uvbhdadqbft2kn4759rodoiivksn9.apps.googleusercontent.com&prompt=consent&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauth%2Fgoogle%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fspreadsheets.google.com%2Ffeeds&state=df37c7da59cf8f7a4899cd5a67a612e9d18946664bc98d4f +Cache-Control: no-cache +X-Request-Id: b511bdb4-c778-4f1a-b5d7-849f1402b1a3 +X-Runtime: 0.003534 +Server: WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08) +Date: Thu, 10 Jul 2014 10:39:34 GMT +Connection: Keep-Alive +Set-Cookie: _lightair_session=Uy9SNDQ1LzZFandLd1g4S2VVTEptR3ZRa0RBcnNFWGtZbG1VZmNKMzc5Z1F6cDFuaHBCa2lScHcxL1FBQ044RTJZMU9iUWF2UitaVjQxcGVzeUZwS0Q3NkdXdzg2SHB6S0IrcU1sR2ExelhRRVZuWFF6MFpraktBMTNCcTM4UVZ5a01ReitYSzNYT2M0dXR1NWViUjhvVGVxUnYwRUtLREtoQUVjMkJPMW1PZG14MUVUQlN0Q2hkRUh5blVLMDZRLS1OZ3JGQXFWQmJKMGNCWGszQWoyMkNRPT0%3D--8345e9f7215c9ef812febd3588c505cfaef628c1; path=/; HttpOnly + +Redirecting to https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367225507767-119uvbhdadqbft2kn4759rodoiivksn9.apps.googleusercontent.com&prompt=consent&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauth%2Fgoogle%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fspreadsheets.google.com%2Ffeeds&state=df37c7da59cf8f7a4899cd5a67a612e9d18946664bc98d4f... diff --git a/spec/controllers/host_response.json b/spec/controllers/host_response.json new file mode 100644 index 0000000..f76a7f1 --- /dev/null +++ b/spec/controllers/host_response.json @@ -0,0 +1,121 @@ +HTTP/1.1 200 OK +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 1; mode=block +X-Content-Type-Options: nosniff +Content-Type: text/html; charset=utf-8 +Etag: "b29936011c26adc86d08ede08dc03e1e" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: cdc9c224-e586-409f-adfb-8367d40f8a41 +X-Runtime: 0.015686 +Server: WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08) +Date: Thu, 10 Jul 2014 10:21:40 GMT +Content-Length: 4406 +Connection: Keep-Alive +Set-Cookie: request_method=GET; path=/ +Set-Cookie: _lightair_session=aUVDRko5L1dYOFJqN2NvNmg2NkI3b2JwN01GRXduamtJdFhmM3hoU0dkR2U3WkpLS2ZUUFlqRWppOGg1NHBPYllDaVpDM2w5d0xxVlBuRFJjaHVFa0FaRVdXOUdQWDlFSGJoaUZTYkdtQnl0N3F3OVdQd1c0YU5rZjNQZ09JcTFmck1HenpMbnhxaHFRT091SnZkdUZRPT0tLTVuczRGVTZyNHdwWXVaZmliU0VxZ0E9PQ%3D%3D--f5a6ab0bbbd0ec42bc63ca27924361e391dd36b3; path=/; HttpOnly + + + + + Lightair + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+
+
+

Insight of LightAir

+

LightAir is a mass Mailer designed to send newsletters designed in html to be sent to a few hundered to a tens of thousands of subscribers. It has an inbuilt HTML editor to create a newsletter online.

+
+
+
+
+ + diff --git a/spec/controllers/spreadsheets_controller_spec.rb b/spec/controllers/spreadsheets_controller_spec.rb new file mode 100644 index 0000000..2df1e40 --- /dev/null +++ b/spec/controllers/spreadsheets_controller_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' +require 'webmock/rspec' + +RSpec.describe SpreadsheetsController, :type => :controller do + google_auth_response = File.new('spec/controllers/google_auth_response.json') + context 'GET Index' do + it 'it renders the index template' do + get :index + expect(response).to render_template(:index) + end + + it 'should return all the spreadhseets' do + c = SpreadsheetsController.new + r = c.instance_eval{index} + expect(r.count).to eq(Spreadsheet.count) + end + end + + context 'GET New' do + it 'opens authentication page on calling auth/google' do + stub_request(:get, 'http://localhost:8080/auth/google/').to_return(google_auth_response) + stub_request(:get, "https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367225507767-119uvbhdadqbft2kn4759rodoiivksn9.apps.googleusercontent.com&prompt=consent&redirect_uri=http://localhost:8080/auth/google/callback&response_type=code&scope=https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/drive%20https://spreadsheets.google.com/feeds&state=df37c7da59cf8f7a4899cd5a67a612e9d18946664bc98d4f"). + with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Cookie'=>'_lightair_session=Uy9SNDQ1LzZFandLd1g4S2VVTEptR3ZRa0RBcnNFWGtZbG1VZmNKMzc5Z1F6cDFuaHBCa2lScHcxL1FBQ044RTJZMU9iUWF2UitaVjQxcGVzeUZwS0Q3NkdXdzg2SHB6S0IrcU1sR2ExelhRRVZuWFF6MFpraktBMTNCcTM4UVZ5a01ReitYSzNYT2M0dXR1NWViUjhvVGVxUnYwRUtLREtoQUVjMkJPMW1PZG14MUVUQlN0Q2hkRUh5blVLMDZRLS1OZ3JGQXFWQmJKMGNCWGszQWoyMkNRPT0=--8345e9f7215c9ef812febd3588c505cfaef628c1', 'User-Agent'=>'Ruby'}). + to_return(:status => 200, :body => "", :headers => {}) + + RestClient.get('http://localhost:8080/auth/google/') + end + end +end diff --git a/spec/factories/spreadsheets.rb b/spec/factories/spreadsheets.rb new file mode 100644 index 0000000..22ce7c5 --- /dev/null +++ b/spec/factories/spreadsheets.rb @@ -0,0 +1,6 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :spreadsheet do + end +end diff --git a/spec/helpers/spreadsheets_helper_spec.rb b/spec/helpers/spreadsheets_helper_spec.rb new file mode 100644 index 0000000..35864e6 --- /dev/null +++ b/spec/helpers/spreadsheets_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the SpreadsheetsHelper. For example: +# +# describe SpreadsheetsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe SpreadsheetsHelper, :type => :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/spreadsheet_spec.rb b/spec/models/spreadsheet_spec.rb new file mode 100644 index 0000000..a4927c8 --- /dev/null +++ b/spec/models/spreadsheet_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Spreadsheet, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cfb18dc..77dfef0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ # The generated `.rspec` file contains `--require spec_helper` which will cause this # file to always be loaded, without a need to explicitly require it in any files. # -# Given that it is always loaded, you are encouraged to keep this file as +# Given th at it is always loaded, you are encouraged to keep this file as # light-weight as possible. Requiring heavyweight dependencies from this file # will add to the boot time of your test suite on EVERY test run, even for an # individual file that may not need all of that loaded. Instead, make a