Permalink
Browse files

~ some fix

  • Loading branch information...
1 parent 16bc832 commit 11ae6fdfbf02dde1e213f6eb49c3144d40558e0c Andrew Zinenko committed Aug 9, 2012
Showing with 33 additions and 21 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 config.yml.example
  3. +1 −3 lib/vk-ruby/core.rb
  4. +5 −1 lib/vk-ruby/middleware/validate_utf.rb
  5. +7 −1 tests/helpers.rb
  6. +15 −16 tests/json_parse_test.rb
View
2 .gitignore
@@ -12,3 +12,5 @@ pkg
\#*
.\#*
*.swp
+
+config.yml
View
3 config.yml.example
@@ -0,0 +1,3 @@
+app_id: 123456
+app_secret: 'secret key'
+access_token: 'token'
View
4 lib/vk-ruby/core.rb
@@ -12,7 +12,7 @@ module VK::Core
attr_configurable :attempts, default: 5
attr_configurable :timeout, default: 2
attr_configurable :open_timeout, default: 3
- attr_configurable :adapter, default: Faraday.default_adapter
+ attr_configurable :adapter, default: Faraday.default_adapter
def_delegators :logger, :debug, :info, :warn, :error, :fatal, :level, :level=
@@ -70,8 +70,6 @@ def faraday_middleware
faraday.response :normalize_utf
faraday.response :validate_utf
- faraday.response :logger
-
faraday.adapter self.adapter
end
end
View
6 lib/vk-ruby/middleware/validate_utf.rb
@@ -9,7 +9,11 @@ def initialize(app)
def call(environment)
@app.call(environment).on_complete do |env|
- puts env[:body] = env[:body].force_encoding('UTF-8').gsub(/[^\x00-\x7F]/,'').chars.select{|i| i.valid_encoding?}.join
+
+ if (env[:body] = env[:body].force_encoding('UTF-8')).valid_encoding?
+ env[:body] = env[:body].chars.select{|i| i.valid_encoding?}.join
+ end
+
env
end
end
View
8 tests/helpers.rb
@@ -1,9 +1,16 @@
require "vk-ruby"
require 'minitest/autorun'
require 'webmock'
+require 'yaml'
include WebMock::API
+#/Users/andrewzinenko/dev/vk-ruby
+
+YAML.load_file("#{Dir.pwd}/config.yml").each do |name, value|
+ self.class.const_set name.upcase, value
+end
+
def create_stubs!
stub_request(:get, /https:\/\/api.vk.com\/method/).to_return(lambda { |request|
{
@@ -78,7 +85,6 @@ def cycle(object, elements, &block)
end
end
-
def random_params(count = 3)
(0...count).inject({}){|hash, num| hash[rand_str] = rand_str; hash}
end
View
31 tests/json_parse_test.rb
@@ -5,9 +5,8 @@ class JsonParseTest < MiniTest::Unit::TestCase
BAD_PROFILES = 21774501...21774512
def setup
- @app = VK::Standalone.new app_id: '2878250',
- app_secret: 'YUvaf67VoJgCuCvm2Rgj',
- access_token: '7bde41fd7eb64c047eb64c04207e9da72e77eb07eb34c1226a10c40cb3418bc'
+ @app = VK::Standalone.new app_id: APP_ID,
+ access_token: ACCESS_TOKEN
@fields = %w[uid first_name last_name nickname screen_name bdate sex city country photo_big has_mobile contacts education rate relation counters]
@@ -16,19 +15,19 @@ def setup
end
[:json_gem, :json_pure, :oj, :yajl].each do |engine|
- defined_method "test_#{engine}" do
-
- MultiJson.engine = engine
-
- BAD_PROFILES.each do |uid|
- assert lambda{|i|
- begin
- @app.getProfiles(uids: i, fields: @fields.join(','), verb: :get); true
- rescue Faraday::Error::ParsingError => ex
- false
- end
- }.call(uid), "#{engine} parsing error"
- end
+ define_method "test_#{engine}" do
+
+ MultiJson.engine = engine
+
+ BAD_PROFILES.each do |uid|
+ assert lambda{|i|
+ begin
+ @app.getProfiles(uids: i, fields: @fields.join(','), verb: :get); true
+ rescue Faraday::Error::ParsingError => ex
+ false
+ end
+ }.call(uid), "#{engine} parsing error"
+ end
end
end

0 comments on commit 11ae6fd

Please sign in to comment.