Permalink
Browse files

Changing some file names and field names for account information.

Using account.yaml for use_saved_session option insetad of environment variable.
  • Loading branch information...
1 parent 8caf13e commit fc048e367c3d9f561828dedfe3fe9c0e322700be @gimite committed Sep 10, 2011
Showing with 26 additions and 25 deletions.
  1. +1 −1 .gitignore
  2. +11 −0 test/account.yaml.example
  3. +0 −3 test/account.yml.template
  4. +14 −21 test/test_google_spreadsheet.rb
View
2 .gitignore
@@ -1,6 +1,6 @@
experiment
doc
-test/account.yml
+test/account.yaml
*~
*.gem
.rvmrc
View
11 test/account.yaml.example
@@ -0,0 +1,11 @@
+# This file is in Public Domain.
+
+# test_google_spreadsheet.rb asks you for your Google account each time by default.
+# If you want to automate it, copy this file to account.yaml and set some proper values.
+
+# Set this to true to store session to $HOME/.ruby_google_spreadsheet.token and reuse it.
+use_saved_session: false
+
+# Or you can write your Google account information here directly.
+mail: "example@gmail.com"
+password: "password"
View
3 test/account.yml.template
@@ -1,3 +0,0 @@
-# Copy the contents of this file to account.yml and set some proper values
-username: "email@example.com"
-password: "password"
View
35 test/test_google_spreadsheet.rb
@@ -10,18 +10,24 @@
class TC_GoogleSpreadsheet < Test::Unit::TestCase
def test_all()
+
puts("This test will create spreadsheets with your account, read/write them")
puts("and finally delete them (if everything goes well).")
- use_saved_session = ENV["GOOGLE_SPREADSHEET_RUBY_USE_SAVED_SESSION"]
- if use_saved_session && !use_saved_session.empty?
+ account_path = File.join(File.dirname(__FILE__), "account.yaml")
+ if File.exist?(account_path)
+ account = YAML.load_file(account_path)
+ else
+ account = {}
+ end
+ if account["use_saved_session"]
session = GoogleSpreadsheet.saved_session
+ elsif account["mail"] && account["password"]
+ session = GoogleSpreadsheet.login(account["mail"], account["password"])
else
- unless session = login_from_fixtures
- highline = HighLine.new()
- mail = highline.ask("Mail: ")
- password = highline.ask("Password: "){ |q| q.echo = false }
- session = GoogleSpreadsheet.login(mail, password)
- end
+ highline = HighLine.new()
+ mail = highline.ask("Mail: ")
+ password = highline.ask("Password: "){ |q| q.echo = false }
+ session = GoogleSpreadsheet.login(mail, password)
end
ss_title = "google-spreadsheet-ruby test " + Time.now.strftime("%Y-%m-%d-%H-%M-%S")
@@ -97,17 +103,4 @@ def test_all()
ss.delete(true)
end
- #######
- private
- #######
-
- def login_from_fixtures
- begin
- fixtures = YAML.load_file(File.join(File.dirname(__FILE__), 'account.yml'))
- rescue
- return false
- end
- GoogleSpreadsheet.login(fixtures["username"], fixtures['password'])
- end
-
end

0 comments on commit fc048e3

Please sign in to comment.