spec/acceptance.tests/users/the_basics_spec.rb in heft-0.0.1 vs spec/acceptance.tests/users/the_basics_spec.rb in heft-0.0.2
- old
+ new
@@ -1,77 +1,35 @@
require 'helper'
-module Heft
- class Users
- require File.join '.', 'adapters', 'internet'
-
- class << self
- def add(opts={})
- headers = {'Authorization' => "HOIST #{ENV['APIKEY']}"}
+describe "Hoistapps and users" do
+ it "can be asked to add a new one" do # see: http://docs.hoi.io/authentication/overview/api/authentication-api
+ email = UniqueEmail.next
- reply = Adapters::Internet.new.execute T::Request.new(
- :headers => headers,
- :uri => 'https://auth.hoi.io/user',
- :body => opts,
- :verb => :post
- )
+ Heft::Users.add :email => email, :password => "xxx_not_a_password_xxx"
- fail "Failed => #{reply.body}" if reply.code > 299
- end
+ expect(Heft::Users.contain? email).to be_true, "User was not found"
+ end
- def contain?(email)
- headers = {'Authorization' => "HOIST #{ENV['APIKEY']}"}
+ it "fails when user exists already with the same email" do
+ email = UniqueEmail.next
- reply = Adapters::Internet.new.execute T::Request.new(
- :headers => headers,
- :uri => 'https://auth.hoi.io/user',
- :body => {:email => email, :password => "******"},
- :verb => :post
- )
+ any_password = "******"
- json = JSON.parse reply.body
+ Heft::Users.add :email => email, :password => any_password
- error_message = json['message']
-
- reply.code === 400 and error_message.match /already a user with that email address/
- end
-
- private
-
- def all
- headers = {'Authorization' => "HOIST #{ENV['APIKEY']}", 'Accept' => 'application/json'}
-
- reply = Adapters::Internet.new.execute T::Request.new(
- :headers => headers,
- :uri => 'https://auth.hoi.io/users',
- )
-
- fail "Failed => #{reply.body}" if reply.code > 299
-
- puts reply.body
- end
- end
+ expect{ Heft::Users.add :email => email, :password => any_password }.to raise_error /already a user with that email address/
end
-end
+
+ it "can delete a user" do
+ email = UniqueEmail.next
-class UniqueEmail
- class << self
- def next
- require 'securerandom'
- "#{SecureRandom.uuid.to_s}@example.test.com"
- end
- end
-end
+ any_password = "******"
-describe "Hoistapps and users" do
- it "can be asked to add a new one" do # see: http://docs.hoi.io/authentication/overview/api/authentication-api
- email = UniqueEmail.next
+ Heft::Users.add :email => email, :password => any_password
- Heft::Users.add :email => email, :password => "xxx_not_a_password_xxx"
+ Heft::Users.delete email
- expect(Heft::Users.contain? email).to be_true, "User was not found"
+ expect{ Heft::Users.add :email => email, :password => any_password }.to_not raise_error
end
-
- it "fails when user exists already with the same email"
- it "can be asked to delete a user"
+
it "fails unless password is <= 6 characters long"
end