Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding some test and the query search for the account.

  • Loading branch information...
commit e5a5c2d4a6657888262a946afbf9f96ad2216ff9 1 parent 1c2bf10
@waratuman waratuman authored
View
3  lib/mls.rb
@@ -6,8 +6,7 @@
require 'yajl'
require 'bigdecimal'
require 'bigdecimal/util'
-require 'active_support'
-require 'active_resource'
+require 'active_support/core_ext'
require 'date'
require 'time'
View
13 lib/mls/models/account.rb
@@ -154,6 +154,19 @@ def update_password!(params_hash)
return false
end
+ def search(terms)
+ results = nil
+ MLS.get('/account/search', :query => terms) do |code, response|
+ case code
+ when 200
+ results = MLS::Account::Parser.parse_collection(response.body)
+ else
+ MLS.handle_response(response)
+ end
+ end
+ results
+ end
+
end
end
View
7 lib/mls/models/user.rb
@@ -1,7 +0,0 @@
-class MLS::User < MLS::Resource
-
- def self.query(q)
- instantiate_collection(get(:query, :query => q))
- end
-
-end
View
4 mls.gemspec
@@ -23,9 +23,11 @@ Gem::Specification.new do |s|
s.add_development_dependency 'bundler'
s.add_development_dependency 'minitest'
s.add_development_dependency 'turn'
+ s.add_development_dependency 'faker'
+ s.add_development_dependency 'factory_girl'
# Runtime
- s.add_runtime_dependency 'activeresource'
+ s.add_runtime_dependency 'activesupport'
s.add_runtime_dependency 'yajl-ruby'
s.add_runtime_dependency 'simplecov'
end
View
12 test/factories/account.rb
@@ -0,0 +1,12 @@
+FactoryGirl.define do
+ factory :account, :class => MLS::Account do
+ name { Faker::Name.name }
+ email { Faker::Internet.email }
+ password { 'test' }
+ password_confirmation 'test'
+ end
+
+ factory :broker, :class => MLS::Account, :parent => :account do
+ role 'broker'
+ end
+end
View
16 test/factories/address.rb
@@ -0,0 +1,16 @@
+FactoryGirl.define do
+ factory :address, :class => MLS::Address do
+ street_number { Kernel.rand(1000).to_s }
+ street { Faker::Address.street_name }
+ neighborhood { Faker::Name.name }
+ city { Faker::Address.city }
+ county { |p| p.city }
+ state { Faker::Address.state_abbr }
+ country 'US'
+ postal_code { Faker::Address.zip_code }
+ formatted_address { |p| "#{p.street_number} #{p.street}, #{p.city}, #{p.state}, #{p.postal_code}" }
+ latitude { Kernel.rand((-90.0)..(90.0)) }
+ longitude { Kernel.rand((-180.0)..(180.0)) }
+ end
+end
+
View
30 test/factories/listing.rb
@@ -0,0 +1,30 @@
+FactoryGirl.define do
+ factory :listing, :class => MLS::Listing do
+ before(:create) { |l|
+ Rails.cache.write('auth_key', MLS.auth_key)
+ MLS.auth_key = l.account.auth_key
+ }
+ after(:create) { |l|
+ MLS.auth_key = Rails.cache.read('auth_key')
+ }
+
+ association :account
+ association :address, :strategy => :build
+
+ #agents_attributes { {'0' => FactoryGirl.attributes_for(:broker)} }
+
+ use 'Office'
+ total_size { Kernel.rand(3000..900000) }
+ maximum_contiguous_size { Kernel.rand(3000..900000) }
+ minimum_divisable_size { Kernel.rand(3000..900000) }
+ kind 'lease'
+ #lease_type { ::MLS::Listing::LEASE_TYPES.sample }
+ space_type 'unit'
+ rate { rand(15..300) }
+ nnn_expenses { |l| l.lease_type == 'NNN' ? Kernel.rand(15..200) : nil }
+ available_on { Time.now + (20 + rand(0..360).to_i).days }
+ sublease_expiration { |l| l.sublease? ? (l.available_on + (30 + Kernel.rand(10..360)).days) : nil }
+ name { |l| l.kind == 'coworking' ? Faker::Name.name : nil }
+ end
+end
+
View
20 test/test_helper.rb
@@ -1,9 +1,15 @@
-require 'simplecov'
-SimpleCov.start do
- add_filter "/test/"
- use_merging true
-end
+# require 'simplecov'
+# SimpleCov.start do
+# add_filter "/test/"
+# use_merging true
+# end
-require 'test/unit'
-require 'turn'
require 'mls'
+require 'turn'
+require 'faker'
+require 'test/unit'
+require 'factory_girl'
+
+puts FactoryGirl.find_definitions
+
+MLS.url = 'http://xSgYUhc1XckzB6glk598XGVDPnGtyLQKItKXgWfP5xcwwjD9XY7O9dWFjVblZA%3D%3D@mls.dev'
View
64 test/units/models/test_account.rb
@@ -1,52 +1,28 @@
require 'test_helper'
class TestAccount < ::Test::Unit::TestCase
-
- def test_properties
- account = MLS::Account.new
-
- assert account.respond_to?(:id)
- assert account.respond_to?(:role)
- assert account.respond_to?(:name)
- assert account.respond_to?(:email)
- assert account.respond_to?(:password)
- assert account.respond_to?(:password_confirmation)
- assert account.respond_to?(:perishable_token)
- assert account.respond_to?(:perishable_token_set_at)
- assert account.respond_to?(:phone)
- assert account.respond_to?(:company)
- assert account.respond_to?(:license)
- assert account.respond_to?(:linkedin)
- assert account.respond_to?(:twitter)
- assert account.respond_to?(:facebook)
- assert account.respond_to?(:web)
- assert account.respond_to?(:mls_number)
- assert account.respond_to?(:state)
- assert account.respond_to?(:country)
- assert account.respond_to?(:auth_key)
- assert account.respond_to?(:funding)
- assert account.respond_to?(:favorite_ids)
- # assert account.respond_to?(:message)
- assert account.respond_to?(:population)
- assert account.respond_to?(:growing)
- assert account.respond_to?(:move_in)
- assert account.respond_to?(:extra_info)
+
+ def test_create_account
+ account = FactoryGirl.create(:account)
+ assert account.id
end
-
- def test_methods
- account = MLS::Account.new
-
- assert account.respond_to?(:update!)
- assert account.respond_to?(:create!)
- assert account.respond_to?(:agent?)
- assert account.respond_to?(:favorites)
- assert account.respond_to?(:favorite)
+
+ def test_create_invalid_account
+ account = FactoryGirl.build(:account, :email => nil)
+ account.save
+ assert account.errors[:email]
+ end
+
+ def test_search_email
+ account = FactoryGirl.create(:account)
+ matches = MLS::Account.search(account.email)
+ assert_equal [account].map(&:id), matches.map(&:id)
end
- def test_class_methods
- assert MLS::Account.respond_to?(:current)
- assert MLS::Account.respond_to?(:authenticate)
- assert MLS::Account.respond_to?(:reset_password!)
- assert MLS::Account.respond_to?(:update_password!)
+ def test_search_name
+ account = FactoryGirl.create(:account)
+ matches = MLS::Account.search(account.name)
+ assert_equal [account].map(&:id), matches.map(&:id)
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.