- Timestamp:
- 04/28/09 16:34:07 (4 years ago)
- Location:
- lang/ruby/hatena_binding
- Files:
-
- 4 modified
-
lib/hatena/haiku/user.rb (modified) (1 diff)
-
lib/hatena/haiku/user/following.rb (modified) (1 diff)
-
test/hatena/haiku/test_user.rb (modified) (3 diffs)
-
test/hatena/haiku/user/test_following.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/hatena_binding/lib/hatena/haiku/user.rb
r32891 r32893 7 7 attr_reader :id 8 8 9 def initialize user 10 @user = user 11 @id = @user.id 9 attr_reader :name 10 11 def initialize id 12 if id.kind_of? Hash 13 init_properties id 14 id = id["id"] 15 end 16 @id = id.dup.freeze 12 17 end 13 18 14 19 def entries 15 Entries.new "/statuses/user_timeline/#{@ user.id}.json?"20 Entries.new "/statuses/user_timeline/#{@id}.json?" 16 21 end 17 22 18 23 def following 19 @following = Following.new selfunless @following24 @following = Following.new @id unless @following 20 25 @following 26 end 27 28 private 29 def init_properties user 30 @name = user["name"].dup.freeze 21 31 end 22 32 end -
lang/ruby/hatena_binding/lib/hatena/haiku/user/following.rb
r32891 r32893 3 3 class User 4 4 class Following 5 def initialize user6 @ user = user5 def initialize id 6 @id = id.dup.freeze 7 7 end 8 8 9 9 def entries 10 Entries.new "/statuses/friends_timeline/#{@ user.id}.json?"10 Entries.new "/statuses/friends_timeline/#{@id}.json?" 11 11 end 12 12 end -
lang/ruby/hatena_binding/test/hatena/haiku/test_user.rb
r32891 r32893 4 4 class TestHatenaUser < Test::Unit::TestCase 5 5 def setup 6 @id = "hatena_user_id" 7 @hatena_user = Hatena::User.new @id 8 @user = Hatena::Haiku::User.new @hatena_user 6 @id = "hid" 7 @user = Hatena::Haiku::User.new @id 9 8 end 10 9 10 # Followingクラスがautoloadされるか 11 11 def test_following 12 assert Hatena::Haiku::User.autoload?(:Following) 12 13 assert_kind_of Class, Hatena::Haiku::User::Following 13 14 end 14 15 15 def test_user_should_have_hatena_user 16 assert_same @hatena_user, @user.__send__(:instance_variable_get, :@user) 16 # id文字列で初期化した場合、その文字列をフリーズして保持する 17 def test_initialize_with_id_should_keep_frozen_id 18 id = "hid" 19 user = Hatena::Haiku::User.new id 20 21 assert_not_same id, user.id 22 assert_equal id, user.id 23 assert user.id.frozen? 17 24 end 18 25 19 def test_id_should_return_hatena_user_id 20 assert_same @hatena_user.id, @user.id 26 # userハッシュで初期化した場合、そのハッシュのidを保持し、それ以外はinit_propertiesメソッドに任せる 27 def test_initialize_with_hash_should_frozen_id_and_call_init_properties 28 $called_args = [] 29 user_class = Class.new(Hatena::Haiku::User) do 30 def init_properties hash 31 $called_args << [:init_properties, hash] 32 end 33 end 34 35 hash = {"id" => "hid"} 36 user = user_class.new hash 37 38 assert_not_same hash["id"], user.id 39 assert_equal hash["id"], user.id 40 assert user.id.frozen? 41 42 assert_equal 1, $called_args.size 43 assert_equal :init_properties, $called_args[0][0] 44 assert_equal hash, $called_args[0][1] 21 45 end 22 46 47 # init_propertiesメソッドは、プロパティを設定する 48 def test_init_properties_should_set_properies 49 hash = { 50 "id" => "hid", 51 "name" => "hname", 52 } 53 @user.__send__(:init_properties, hash) 54 55 assert_not_same hash["name"], @user.name 56 assert_equal hash["name"], @user.name 57 assert @user.name.frozen? 58 end 59 60 # entriesメソッドはEntriesインスタンスを返すこと 23 61 def test_entries_should_return_entries_class 24 62 entries = @user.entries … … 26 64 end 27 65 28 def test_entries_should_set_user_timeline 66 # entriesメソッドはユーザIDを含んだパスを設定すること 67 def test_entries_should_set_path_user_timeline 29 68 entries = @user.entries 30 assert_equal "/statuses/user_timeline/ hatena_user_id.json?", entries.__send__(:instance_variable_get, :@path)69 assert_equal "/statuses/user_timeline/#{@id}.json?", entries.__send__(:instance_variable_get, :@path) 31 70 end 32 71 72 # followingメソッドはFollowingインスタンスを返すこと 33 73 def test_following_should_return_following_class 34 74 following = @user.following … … 36 76 end 37 77 38 def test_following_should_set_user 78 # followingメソッドはユーザIDを設定すること 79 def test_following_should_set_user_id 39 80 following = @user.following 40 assert_ same @user, following.__send__(:instance_variable_get, :@user)81 assert_equal @user.id, following.__send__(:instance_variable_get, :@id) 41 82 end 42 83 end -
lang/ruby/hatena_binding/test/hatena/haiku/user/test_following.rb
r32891 r32893 4 4 class TestHatenaUserFollowing < Test::Unit::TestCase 5 5 def setup 6 @id = "hatena_user_id" 7 @hatena_user = Hatena::User.new @id 8 @user = Hatena::Haiku::User.new @hatena_user 9 @following = Hatena::Haiku::User::Following.new(@user) 6 @id = "hid" 7 @following = Hatena::Haiku::User::Following.new @id 10 8 end 11 9 12 def test_following_should_have_user 13 assert_same @user, @following.__send__(:instance_variable_get, :@user) 10 # id文字列で初期化した場合、その文字列をフリーズして保持する 11 def test_initialize_with_id_should_keep_frozen_id 12 id = @following.__send__(:instance_variable_get, :@id) 13 14 assert_not_same @id, id 15 assert_equal @id, id 16 assert id.frozen? 14 17 end 15 18 19 # entriesメソッドはEntriesインスタンスを返すこと 16 20 def test_entries_should_return_entries_class 17 21 entries = @following.entries … … 19 23 end 20 24 21 def test_entries_should_return_entries_class 25 # entriesメソッドはユーザIDを含んだパスを設定すること 26 def test_entries_should_set_path_friends_timeline 22 27 entries = @following.entries 23 assert_equal "/statuses/friends_timeline/ hatena_user_id.json?", entries.__send__(:instance_variable_get, :@path)28 assert_equal "/statuses/friends_timeline/#{@id}.json?", entries.__send__(:instance_variable_get, :@path) 24 29 end 25 30 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)