Sha256: 1578134d98ff375e1f3580d33be64e5d32b5c4e51b35683d620661d596dbf4b1

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe "Integration" do
  before(:all) do
    VkontakteApi.register_alias
    # turn off all the logging
    VK.configure do |config|
      config.log_requests  = false
      config.log_errors    = false
      config.log_responses = false
    end
  end
  
  describe "unauthorized requests" do
    let(:vk) { VK::Client.new }
    
    it "get users" do
      user = vk.users.get(uid: 1).first
      expect(user.uid).to eq(1)
      expect(user.last_name).not_to be_empty
      expect(user.first_name).not_to be_empty
    end
    
    it "search newsfeed" do
      news = vk.newsfeed.search(q: 'vk', count: 1)
      expect(news).to be_a(Enumerable)
    end
  end
  
  if MechanizedAuthorization.on?
    describe "authorized requests" do
      let(:vk) { MechanizedAuthorization.client }
      
      it "get groups" do
        expect(vk.groups.get).to include(1)
      end
    end
    
    describe "requests with camelCase and predicate methods" do
      let(:vk) { MechanizedAuthorization.client }
      
      it "convert method names to vk.com format" do
        expect(vk.is_app_user?).to be_true
      end
    end
  end
  
  describe "requests with array arguments" do
    let(:vk) { VK::Client.new }
    
    it "join arrays with a comma" do
      users = vk.users.get(uids: [1, 2, 3], fields: %w[first_name last_name screen_name])
      expect(users.first.screen_name).not_to be_empty
    end
  end
  
  describe "requests with blocks" do
    let(:vk) { VK::Client.new }
    
    it "map the result with a block" do
      users = vk.users.get(uid: 1) do |user|
        "#{user.last_name} #{user.first_name}"
      end
      
      expect(users.first).not_to be_empty
    end
  end
  
  describe "authorization" do
    context "with a scope" do
      it "returns a correct url" do
        url = VK.authorization_url(scope: %w[friends groups])
        expect(url).to include('scope=friends%2Cgroups')
      end
    end
  end
  
  after(:all) do
    VK.reset
    VK.unregister_alias
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vkontakte_api-1.4 spec/integration_spec.rb