/spec/octopus/association_spec.rb

https://github.com/GunioRobot/octopus · Ruby · 657 lines · 559 code · 98 blank · 0 comment · 121 complexity · 010844f5cadaf3a808aa531b8571764b MD5 · raw file

  1. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
  2. describe Octopus::Association do
  3. describe "when you have a 1 x 1 relationship" do
  4. before(:each) do
  5. @computer_brazil = Computer.using(:brazil).create!(:name => "Computer Brazil")
  6. @computer_master = Computer.create!(:name => "Computer Brazil")
  7. @keyboard_brazil = Keyboard.using(:brazil).create!(:name => "Keyboard Brazil", :computer => @computer_brazil)
  8. @keyboard_master = Keyboard.create!(:name => "Keyboard Master", :computer => @computer_master)
  9. end
  10. it "should find the models" do
  11. @keyboard_master.computer.should == @computer_master
  12. @keyboard_brazil.computer.should == @computer_brazil
  13. end
  14. it "should read correctly the relationed model" do
  15. new_computer_brazil = Computer.using(:brazil).create!(:name => "New Computer Brazil")
  16. new_computer_master = Computer.create!(:name => "New Computer Brazil")
  17. @keyboard_brazil.computer = new_computer_brazil
  18. @keyboard_brazil.save()
  19. @keyboard_brazil.reload
  20. @keyboard_brazil.computer_id.should == new_computer_brazil.id
  21. @keyboard_brazil.computer.should == new_computer_brazil
  22. new_computer_brazil.save()
  23. new_computer_brazil.reload
  24. new_computer_brazil.keyboard.should == @keyboard_brazil
  25. end
  26. it "should work when using #build_computer or #build_keyboard" do
  27. c = Computer.using(:brazil).create!(:name => "Computer Brazil")
  28. k = c.build_keyboard(:name => "Building keyboard")
  29. c.save()
  30. k.save()
  31. c.keyboard.should == k
  32. k.computer_id.should == c.id
  33. k.computer.should == c
  34. end
  35. it "should work when using #create_computer or #create_keyboard" do
  36. c = Computer.using(:brazil).create!(:name => "Computer Brazil")
  37. k = c.create_keyboard(:name => "Building keyboard")
  38. c.save()
  39. k.save()
  40. c.keyboard.should == k
  41. k.computer_id.should == c.id
  42. k.computer.should == c
  43. end
  44. end
  45. describe "when you have a N x N reliationship" do
  46. before(:each) do
  47. @brazil_role = Role.using(:brazil).create!(:name => "Brazil Role")
  48. @master_role = Role.create!(:name => "Master Role")
  49. @permission_brazil = Permission.using(:brazil).create!(:name => "Brazil Permission")
  50. @permission_master = Permission.using(:master).create!(:name => "Master Permission")
  51. @brazil_role.permissions << @permission_brazil
  52. @brazil_role.save()
  53. Client.using(:master).create!(:name => "teste")
  54. end
  55. it "should find all models in the specified shard" do
  56. @brazil_role.permission_ids().should == [@permission_brazil.id]
  57. @brazil_role.permissions().should == [@permission_brazil]
  58. end
  59. it "should finds the client that the item belongs" do
  60. @permission_brazil.role_ids.should == [@brazil_role.id]
  61. @permission_brazil.roles.should == [@brazil_role]
  62. end
  63. it "should update the attribute for the item" do
  64. new_brazil_role = Role.using(:brazil).create!(:name => "new Role")
  65. @permission_brazil.roles = [new_brazil_role]
  66. @permission_brazil.roles.should == [new_brazil_role]
  67. @permission_brazil.save()
  68. @permission_brazil.reload
  69. @permission_brazil.role_ids.should == [new_brazil_role.id]
  70. @permission_brazil.roles().should == [new_brazil_role]
  71. end
  72. it "should works for build method" do
  73. new_brazil_role = Role.using(:brazil).create!(:name => "Brazil Role")
  74. c = new_brazil_role.permissions.create(:name => "new Permission")
  75. c.save()
  76. new_brazil_role.save()
  77. c.roles().should == [new_brazil_role]
  78. new_brazil_role.permissions.should == [c]
  79. end
  80. describe "it should works when using" do
  81. before(:each) do
  82. @permission_brazil_2 = Permission.using(:brazil).create!(:name => "Brazil Item 2")
  83. @role = Role.using(:brazil).create!(:name => "testes")
  84. end
  85. it "update_attributes" do
  86. @permission_brazil_2.update_attributes(:role_ids => [@role.id])
  87. @permission_brazil_2.roles.to_set.should == [@role].to_set
  88. end
  89. if !Octopus.rails3?
  90. it "update_attribute" do
  91. @permission_brazil_2.update_attribute(:role_ids, [@role.id])
  92. @permission_brazil_2.roles.to_set.should == [@role].to_set
  93. end
  94. end
  95. it "<<" do
  96. @permission_brazil_2.roles << @role
  97. @role.save()
  98. @permission_brazil_2.save()
  99. @permission_brazil_2.reload
  100. @permission_brazil_2.roles.to_set.should == [@role].to_set
  101. end
  102. it "build" do
  103. role = @permission_brazil_2.roles.build(:name => "Builded Role")
  104. @permission_brazil_2.save()
  105. @permission_brazil_2.roles.to_set.should == [role].to_set
  106. end
  107. it "create" do
  108. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  109. @permission_brazil_2.roles.to_set.should == [role].to_set
  110. end
  111. it "create" do
  112. role = @permission_brazil_2.roles.create!(:name => "Builded Role")
  113. @permission_brazil_2.roles.to_set.should == [role].to_set
  114. end
  115. it "count" do
  116. @permission_brazil_2.roles.count.should == 0
  117. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  118. @permission_brazil_2.roles.count.should == 1
  119. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  120. @permission_brazil_2.roles.count.should == 2
  121. end
  122. it "size" do
  123. @permission_brazil_2.roles.size.should == 0
  124. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  125. @permission_brazil_2.roles.size.should == 1
  126. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  127. @permission_brazil_2.roles.size.should == 2
  128. end
  129. it "length" do
  130. @permission_brazil_2.roles.length.should == 0
  131. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  132. @permission_brazil_2.roles.length.should == 1
  133. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  134. @permission_brazil_2.roles.length.should == 2
  135. end
  136. it "empty?" do
  137. @permission_brazil_2.roles.empty?.should be_true
  138. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  139. @permission_brazil_2.roles.empty?.should be_false
  140. end
  141. it "delete_all" do
  142. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  143. @permission_brazil_2.roles.empty?.should be_false
  144. @permission_brazil_2.roles.delete_all
  145. @permission_brazil_2.roles.empty?.should be_true
  146. end
  147. it "destroy_all" do
  148. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  149. @permission_brazil_2.roles.empty?.should be_false
  150. @permission_brazil_2.roles.destroy_all
  151. @permission_brazil_2.roles.empty?.should be_true
  152. end
  153. it "find" do
  154. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  155. @permission_brazil_2.roles.find(:first).should == role
  156. @permission_brazil_2.roles.destroy_all
  157. @permission_brazil_2.roles.find(:first).should be_nil
  158. end
  159. it "exists?" do
  160. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  161. @permission_brazil_2.roles.exists?(role).should be_true
  162. @permission_brazil_2.roles.destroy_all
  163. @permission_brazil_2.roles.exists?(role).should be_false
  164. end
  165. it "clear" do
  166. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  167. @permission_brazil_2.roles.empty?.should be_false
  168. @permission_brazil_2.roles.clear
  169. @permission_brazil_2.roles.empty?.should be_true
  170. end
  171. it "delete" do
  172. role = @permission_brazil_2.roles.create(:name => "Builded Role")
  173. @permission_brazil_2.roles.empty?.should be_false
  174. @permission_brazil_2.roles.delete(role)
  175. @permission_brazil_2.reload
  176. @role.reload
  177. @role.permissions.should == []
  178. @permission_brazil_2.roles.should == []
  179. end
  180. end
  181. end
  182. describe "when you have has_many :through" do
  183. before(:each) do
  184. @programmer = Programmer.using(:brazil).create!(:name => "Thiago")
  185. @project = Project.using(:brazil).create!(:name => "RubySoc")
  186. @project2 = Project.using(:brazil).create!(:name => "Cobol Application")
  187. @programmer.projects << @project
  188. @programmer.save()
  189. Project.using(:master).create!(:name => "Project Master")
  190. end
  191. it "should find all models in the specified shard" do
  192. @programmer.project_ids().should == [ @project.id]
  193. @programmer.projects().should == [@project]
  194. end
  195. it "should update the attribute for the item" do
  196. new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Joao")
  197. @project.programmers = [new_brazil_programmer]
  198. @project.programmers.should == [new_brazil_programmer]
  199. @project.save()
  200. @project.reload
  201. @project.programmer_ids.should == [new_brazil_programmer.id]
  202. @project.programmers().should == [new_brazil_programmer]
  203. end
  204. it "should works for create method" do
  205. new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Joao")
  206. c = new_brazil_programmer.projects.create(:name => "new Project")
  207. c.save()
  208. new_brazil_programmer.save()
  209. c.programmers().should == [new_brazil_programmer]
  210. new_brazil_programmer.projects.should == [c]
  211. end
  212. describe "it should works when using" do
  213. before(:each) do
  214. @new_brazil_programmer = Programmer.using(:brazil).create!(:name => "Jose")
  215. @project = Project.using(:brazil).create!(:name => "VB Application :-(")
  216. end
  217. it "update_attributes" do
  218. @new_brazil_programmer.update_attributes(:project_ids => [@project.id])
  219. @new_brazil_programmer.projects.to_set.should == [@project].to_set
  220. end
  221. if !Octopus.rails3?
  222. it "update_attribute" do
  223. @new_brazil_programmer.update_attribute(:project_ids, [@project.id])
  224. @new_brazil_programmer.projects.to_set.should == [@project].to_set
  225. end
  226. end
  227. it "<<" do
  228. @new_brazil_programmer.projects << @project
  229. @project.save()
  230. @new_brazil_programmer.save()
  231. @new_brazil_programmer.reload
  232. @new_brazil_programmer.projects.to_set.should == [@project].to_set
  233. end
  234. it "build" do
  235. role = @new_brazil_programmer.projects.build(:name => "New VB App :-/")
  236. @new_brazil_programmer.save()
  237. @new_brazil_programmer.projects.to_set.should == [role].to_set
  238. end
  239. it "create" do
  240. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  241. @new_brazil_programmer.projects.to_set.should == [role].to_set
  242. end
  243. it "create" do
  244. role = @new_brazil_programmer.projects.create!(:name => "New VB App :-/")
  245. @new_brazil_programmer.projects.to_set.should == [role].to_set
  246. end
  247. it "count" do
  248. @new_brazil_programmer.projects.count.should == 0
  249. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  250. @new_brazil_programmer.projects.count.should == 1
  251. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  252. @new_brazil_programmer.projects.count.should == 2
  253. end
  254. it "size" do
  255. @new_brazil_programmer.projects.size.should == 0
  256. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  257. @new_brazil_programmer.projects.size.should == 1
  258. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  259. @new_brazil_programmer.projects.size.should == 2
  260. end
  261. it "length" do
  262. @new_brazil_programmer.projects.length.should == 0
  263. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  264. @new_brazil_programmer.projects.length.should == 1
  265. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  266. @new_brazil_programmer.projects.length.should == 2
  267. end
  268. it "empty?" do
  269. @new_brazil_programmer.projects.empty?.should be_true
  270. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  271. @new_brazil_programmer.projects.empty?.should be_false
  272. end
  273. it "delete_all" do
  274. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  275. @new_brazil_programmer.projects.empty?.should be_false
  276. @new_brazil_programmer.projects.delete_all
  277. @new_brazil_programmer.projects.empty?.should be_true
  278. end
  279. it "destroy_all" do
  280. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  281. @new_brazil_programmer.projects.empty?.should be_false
  282. @new_brazil_programmer.projects.destroy_all
  283. @new_brazil_programmer.projects.empty?.should be_true
  284. end
  285. it "find" do
  286. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  287. @new_brazil_programmer.projects.find(:first).should == role
  288. @new_brazil_programmer.projects.destroy_all
  289. @new_brazil_programmer.projects.find(:first).should be_nil
  290. end
  291. it "exists?" do
  292. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  293. @new_brazil_programmer.projects.exists?(role).should be_true
  294. @new_brazil_programmer.projects.destroy_all
  295. @new_brazil_programmer.projects.exists?(role).should be_false
  296. end
  297. it "clear" do
  298. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  299. @new_brazil_programmer.projects.empty?.should be_false
  300. @new_brazil_programmer.projects.clear
  301. @new_brazil_programmer.projects.empty?.should be_true
  302. end
  303. it "delete" do
  304. role = @new_brazil_programmer.projects.create(:name => "New VB App :-/")
  305. @new_brazil_programmer.projects.empty?.should be_false
  306. @new_brazil_programmer.projects.delete(role)
  307. @new_brazil_programmer.reload
  308. @project.reload
  309. @project.programmers.should == []
  310. @new_brazil_programmer.projects.should == []
  311. end
  312. end
  313. end
  314. describe "when you have a 1 x N relationship" do
  315. before(:each) do
  316. @brazil_client = Client.using(:brazil).create!(:name => "Brazil Client")
  317. @master_client = Client.create!(:name => "Master Client")
  318. @item_brazil = Item.using(:brazil).create!(:name => "Brazil Item", :client => @brazil_client)
  319. @item_master = Item.create!(:name => "Master Item", :client => @master_client)
  320. @brazil_client = Client.using(:brazil).find_by_name("Brazil Client")
  321. Client.using(:master).create!(:name => "teste")
  322. end
  323. it "should find all models in the specified shard" do
  324. @brazil_client.item_ids.should == [@item_brazil.id]
  325. @brazil_client.items().should == [@item_brazil]
  326. end
  327. it "should finds the client that the item belongs" do
  328. @item_brazil.client.should == @brazil_client
  329. end
  330. it "should raise error if you try to add a record from a different shard" do
  331. lambda do
  332. @brazil_client.items << Item.using(:canada).create!(:name => "New User")
  333. end.should raise_error("Association Error: Records are from different shards")
  334. end
  335. it "should update the attribute for the item" do
  336. new_brazil_client = Client.using(:brazil).create!(:name => "new Client")
  337. @item_brazil.client = new_brazil_client
  338. @item_brazil.client.should == new_brazil_client
  339. @item_brazil.save()
  340. @item_brazil.reload
  341. @item_brazil.client_id.should == new_brazil_client.id
  342. @item_brazil.client().should == new_brazil_client
  343. end
  344. it "should works for build method" do
  345. item2 = Item.using(:brazil).create!(:name => "Brazil Item")
  346. c = item2.create_client(:name => "new Client")
  347. c.save()
  348. item2.save()
  349. item2.client.should == c
  350. c.items().should == [item2]
  351. end
  352. describe "it should works when using" do
  353. before(:each) do
  354. @item_brazil_2 = Item.using(:brazil).create!(:name => "Brazil Item 2")
  355. @brazil_client.items.to_set.should == [@item_brazil].to_set
  356. end
  357. it "update_attributes" do
  358. @brazil_client.update_attributes(:item_ids => [@item_brazil_2.id, @item_brazil.id])
  359. @brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
  360. end
  361. if !Octopus.rails3?
  362. it "update_attribute" do
  363. @brazil_client.update_attribute(:item_ids, [@item_brazil_2.id, @item_brazil.id])
  364. @brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
  365. end
  366. end
  367. it "<<" do
  368. @brazil_client.items << @item_brazil_2
  369. @brazil_client.items.to_set.should == [@item_brazil, @item_brazil_2].to_set
  370. end
  371. it "build" do
  372. item = @brazil_client.items.build(:name => "Builded Item")
  373. item.save()
  374. @brazil_client.items.to_set.should == [@item_brazil, item].to_set
  375. end
  376. it "create" do
  377. item = @brazil_client.items.create(:name => "Builded Item")
  378. @brazil_client.items.to_set.should == [@item_brazil, item].to_set
  379. end
  380. it "count" do
  381. @brazil_client.items.count.should == 1
  382. item = @brazil_client.items.create(:name => "Builded Item")
  383. @brazil_client.items.count.should == 2
  384. end
  385. it "size" do
  386. @brazil_client.items.size.should == 1
  387. item = @brazil_client.items.create(:name => "Builded Item")
  388. @brazil_client.items.size.should == 2
  389. end
  390. it "create!" do
  391. item = @brazil_client.items.create!(:name => "Builded Item")
  392. @brazil_client.items.to_set.should == [@item_brazil, item].to_set
  393. end
  394. it "length" do
  395. @brazil_client.items.length.should == 1
  396. item = @brazil_client.items.create(:name => "Builded Item")
  397. @brazil_client.items.length.should == 2
  398. end
  399. it "empty?" do
  400. @brazil_client.items.empty?.should be_false
  401. c = Client.create!(:name => "Client1")
  402. c.items.empty?.should be_true
  403. end
  404. it "delete" do
  405. @brazil_client.items.empty?.should be_false
  406. @brazil_client.items.delete(@item_brazil)
  407. @brazil_client.reload
  408. @item_brazil.reload
  409. @item_brazil.client.should be_nil
  410. @brazil_client.items.should == []
  411. @brazil_client.items.empty?.should be_true
  412. end
  413. it "delete_all" do
  414. @brazil_client.items.empty?.should be_false
  415. @brazil_client.items.delete_all
  416. @brazil_client.items.empty?.should be_true
  417. end
  418. it "destroy_all" do
  419. @brazil_client.items.empty?.should be_false
  420. @brazil_client.items.destroy_all
  421. @brazil_client.items.empty?.should be_true
  422. end
  423. it "find" do
  424. @brazil_client.items.find(:first).should == @item_brazil
  425. @brazil_client.items.destroy_all
  426. @brazil_client.items.find(:first).should be_nil
  427. end
  428. it "exists?" do
  429. @brazil_client.items.exists?(@item_brazil).should be_true
  430. @brazil_client.items.destroy_all
  431. @brazil_client.items.exists?(@item_brazil).should be_false
  432. end
  433. it "uniq" do
  434. @brazil_client.items.uniq.should == [@item_brazil]
  435. end
  436. it "clear" do
  437. @brazil_client.items.empty?.should be_false
  438. @brazil_client.items.clear
  439. @brazil_client.items.empty?.should be_true
  440. end
  441. end
  442. end
  443. describe "when you have a 1 x N polymorphic relationship" do
  444. before(:each) do
  445. @brazil_client = Client.using(:brazil).create!(:name => "Brazil Client")
  446. @master_client = Client.create!(:name => "Master Client")
  447. @comment_brazil = Comment.using(:brazil).create!(:name => "Brazil Comment", :commentable => @brazil_client)
  448. @comment_master = Comment.create!(:name => "Master Comment", :commentable => @master_client)
  449. @brazil_client = Client.using(:brazil).find_by_name("Brazil Client")
  450. Client.using(:master).create!(:name => "teste")
  451. end
  452. it "should find all models in the specified shard" do
  453. @brazil_client.comment_ids.should == [@comment_brazil.id]
  454. @brazil_client.comments().should == [@comment_brazil]
  455. end
  456. it "should finds the client that the comment belongs" do
  457. @comment_brazil.commentable.should == @brazil_client
  458. end
  459. it "should update the attribute for the comment" do
  460. new_brazil_client = Client.using(:brazil).create!(:name => "new Client")
  461. @comment_brazil.commentable = new_brazil_client
  462. @comment_brazil.commentable.should == new_brazil_client
  463. @comment_brazil.save()
  464. @comment_brazil.reload
  465. @comment_brazil.commentable_id.should == new_brazil_client.id
  466. @comment_brazil.commentable().should == new_brazil_client
  467. end
  468. describe "it should works when using" do
  469. before(:each) do
  470. @comment_brazil_2 = Comment.using(:brazil).create!(:name => "Brazil Comment 2")
  471. @brazil_client.comments.to_set.should == [@comment_brazil].to_set
  472. end
  473. it "update_attributes" do
  474. @brazil_client.update_attributes(:comment_ids => [@comment_brazil_2.id, @comment_brazil.id])
  475. @brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
  476. end
  477. if !Octopus.rails3?
  478. it "update_attribute" do
  479. @brazil_client.update_attribute(:comment_ids, [@comment_brazil_2.id, @comment_brazil.id])
  480. @brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
  481. end
  482. end
  483. it "<<" do
  484. @brazil_client.comments << @comment_brazil_2
  485. @brazil_client.comments.to_set.should == [@comment_brazil, @comment_brazil_2].to_set
  486. end
  487. it "build" do
  488. comment = @brazil_client.comments.build(:name => "Builded Comment")
  489. comment.save()
  490. @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
  491. end
  492. it "create" do
  493. comment = @brazil_client.comments.create(:name => "Builded Comment")
  494. @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
  495. end
  496. it "count" do
  497. @brazil_client.comments.count.should == 1
  498. comment = @brazil_client.comments.create(:name => "Builded Comment")
  499. @brazil_client.comments.count.should == 2
  500. end
  501. it "size" do
  502. @brazil_client.comments.size.should == 1
  503. comment = @brazil_client.comments.create(:name => "Builded Comment")
  504. @brazil_client.comments.size.should == 2
  505. end
  506. it "create!" do
  507. comment = @brazil_client.comments.create!(:name => "Builded Comment")
  508. @brazil_client.comments.to_set.should == [@comment_brazil, comment].to_set
  509. end
  510. it "length" do
  511. @brazil_client.comments.length.should == 1
  512. comment = @brazil_client.comments.create(:name => "Builded Comment")
  513. @brazil_client.comments.length.should == 2
  514. end
  515. it "empty?" do
  516. @brazil_client.comments.empty?.should be_false
  517. c = Client.create!(:name => "Client1")
  518. c.comments.empty?.should be_true
  519. end
  520. it "delete" do
  521. @brazil_client.comments.empty?.should be_false
  522. @brazil_client.comments.delete(@comment_brazil)
  523. @brazil_client.reload
  524. @comment_brazil.reload
  525. @comment_brazil.commentable.should be_nil
  526. @brazil_client.comments.should == []
  527. @brazil_client.comments.empty?.should be_true
  528. end
  529. it "delete_all" do
  530. @brazil_client.comments.empty?.should be_false
  531. @brazil_client.comments.delete_all
  532. @brazil_client.comments.empty?.should be_true
  533. end
  534. it "destroy_all" do
  535. @brazil_client.comments.empty?.should be_false
  536. @brazil_client.comments.destroy_all
  537. @brazil_client.comments.empty?.should be_true
  538. end
  539. it "find" do
  540. @brazil_client.comments.find(:first).should == @comment_brazil
  541. @brazil_client.comments.destroy_all
  542. @brazil_client.comments.find(:first).should be_nil
  543. end
  544. it "exists?" do
  545. @brazil_client.comments.exists?(@comment_brazil).should be_true
  546. @brazil_client.comments.destroy_all
  547. @brazil_client.comments.exists?(@comment_brazil).should be_false
  548. end
  549. it "uniq" do
  550. @brazil_client.comments.uniq.should == [@comment_brazil]
  551. end
  552. it "clear" do
  553. @brazil_client.comments.empty?.should be_false
  554. @brazil_client.comments.clear
  555. @brazil_client.comments.empty?.should be_true
  556. end
  557. end
  558. end
  559. end