test/unit/etsy/user_test.rb in etsy-0.1.0 vs test/unit/etsy/user_test.rb in etsy-0.2.0

- old
+ new

@@ -1,75 +1,79 @@ -require File.dirname(__FILE__) + '/../../test_helper' +require File.expand_path('../../../test_helper', __FILE__) module Etsy class UserTest < Test::Unit::TestCase - describe "The User class" do - - it "should be able to find a user by username" do - response = mock_request_cycle :for => '/users/littletjane', :data => 'getUserDetails' - - User.expects(:new).with(response.result).returns('user') - User.find_by_username('littletjane').should == 'user' + context "The User class" do + + should "be able to find a single user" do + users = mock_request('/users/littletjane', {}, 'User', 'getUser.single.json') + User.find('littletjane').should == users.first end - - end - - describe "An instance of the User class" do - - when_populating User, :from => 'getUserDetails' do - - value_for :username, :is => 'littletjane' - value_for :id, :is => 5327518 - value_for :url, :is => 'http://www.etsy.com/shop.php?user_id=5327518' - value_for :joined, :is => 1191381757.93 - value_for :city, :is => 'Washington, DC' - value_for :gender, :is => 'female' - value_for :seller, :is => true - value_for :last_login, :is => 1239797927.39 - value_for :bio, :is => 'hello!' - + + should "be able to find multiple users" do + users = mock_request('/users/littletjane,reagent', {}, 'User', 'getUser.multiple.json') + User.find('littletjane', 'reagent').should == users end - it "should know if it is a seller" do - user = User.new - user.expects(:seller).with().returns(true) - user.seller?.should be(true) + should "be able to find the current logged in user" do + oauth_keys = {:access_token => 'token', :access_secret => 'secret'} + users = mock_request('/users/__SELF__', oauth_keys, 'User', 'getUser.single.json') + User.myself('token', 'secret').should == users.first end - - it "should know the join date" do - user = User.new - user.stubs(:joined).with().returns(1191381757.93) - - user.joined_at.should == Time.at(1191381757.93) + end + + context "An instance of the User class" do + + context "with public response data" do + setup do + data = read_fixture('user/getUser.single.json') + @user = User.new(data.first) + end + + should "have an ID" do + @user.id.should == 5327518 + end + + should "have a :username" do + @user.username.should == 'littletjane' + end + + should "have a value for :created" do + @user.created.should == 1191381578 + end + + should "not have an email address" do + @user.email.should be_nil + end end - - it "should know the last login date" do - user = User.new - user.stubs(:last_login).with().returns(1239797927.39) - - user.last_login_at.should == Time.at(1239797927.39) + + context "with private response data" do + setup do + data = read_fixture('user/getUser.single.private.json') + @user = User.new(data.first) + end + + should "have an email address" do + @user.email.should == 'reaganpr@gmail.com' + end end - - it "should have a shop" do + + should "know when the user was created" do user = User.new - shop = stub() - - user.stubs(:id).with().returns(1) - user.stubs(:seller?).with().returns(true) - - Shop.expects(:find_by_user_id).with(1).returns(shop) - - user.shop.should == shop + user.stubs(:created).returns(1) + + user.created_at.should == Time.at(1) end - - it "should not have a shop if the user is not a seller" do - user = User.new - user.expects(:seller?).with().returns(false) - - user.shop.should be(nil) - end - end - + + should "know the shop for a user" do + user = User.new + user.stubs(:username).with().returns('username') + + Shop.stubs(:find).with('username').returns('shop') + + user.shop.should == 'shop' + end + end -end \ No newline at end of file +end