inkwell 1.1.1 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -5,24 +5,28 @@ describe "Community" do
5
5
  @salkar = User.create :nick => "Salkar"
6
6
  @morozovm = User.create :nick => "Morozovm"
7
7
  @talisman = User.create :nick => "Talisman"
8
+ @spy = User.create :nick => "Spy"
8
9
  @community_1 = Community.create :name => "Community_1", :owner_id => @talisman.id
9
10
  @salkar_post = @salkar.posts.create :body => "salkar_post_test_body"
11
+ @salkar.reload
12
+ @talisman.reload
13
+ @morozovm.reload
10
14
  end
11
15
 
12
16
  it "user should been added to community" do
13
17
  users_ids = ActiveSupport::JSON.decode @community_1.users_ids
14
18
  users_ids.size.should == 1
15
- communities_ids = ActiveSupport::JSON.decode @salkar.communities_ids
16
- communities_ids.size.should == 0
19
+ communities_info = ActiveSupport::JSON.decode @salkar.communities_info
20
+ communities_info.size.should == 0
17
21
  @community_1.add_user :user => @salkar
18
22
  @community_1.reload
19
23
  @salkar.reload
20
24
  users_ids = ActiveSupport::JSON.decode @community_1.users_ids
21
25
  users_ids.size.should == 2
22
26
  users_ids[1].should == @salkar.id
23
- communities_ids = ActiveSupport::JSON.decode @salkar.communities_ids
24
- communities_ids.size.should == 1
25
- communities_ids[0].should == @community_1.id
27
+ communities_info = ActiveSupport::JSON.decode @salkar.communities_info
28
+ communities_info.size.should == 1
29
+ communities_info[0].should == {"c_id"=>@community_1.id, "a"=>"w"}
26
30
  end
27
31
 
28
32
  it "community's posts should been transferred to user timeline" do
@@ -144,7 +148,7 @@ describe "Community" do
144
148
 
145
149
  it "user should be in community after added (include_user?)" do
146
150
  @community_1.include_user?(@salkar).should == false
147
- @salkar.communities_ids = "[#{@community_1.id}]"
151
+ @salkar.communities_info = ActiveSupport::JSON.encode [{"c_id"=>@community_1.id, "a"=>"w"}]
148
152
  @community_1.users_ids = "[#{@salkar.id}]"
149
153
  @community_1.save
150
154
  @salkar.save
@@ -156,10 +160,9 @@ describe "Community" do
156
160
  end
157
161
 
158
162
  it "user should be admin" do
159
- @salkar.admin_of = ActiveSupport::JSON.encode [{'community_id' => @salkar.id}]
160
- @salkar.save
161
- @community_1.admins_info = ActiveSupport::JSON.encode [{'user_id' => @salkar.id}]
163
+ @community_1.admins_info = ActiveSupport::JSON.encode [{'admin_id' => @salkar.id}]
162
164
  @community_1.save
165
+ @community_1.reload
163
166
  @community_1.include_admin?(@salkar).should == true
164
167
  end
165
168
 
@@ -173,7 +176,6 @@ describe "Community" do
173
176
  @salkar.reload
174
177
  @community_1.include_user?(@salkar).should == false
175
178
  ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1
176
- ActiveSupport::JSON.decode(@salkar.admin_of).size.should == 0
177
179
  end
178
180
 
179
181
  it "community owner should not remove himself from community" do
@@ -245,8 +247,6 @@ describe "Community" do
245
247
  end
246
248
 
247
249
  it "admin level of user should be returned" do
248
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 3}]
249
- @salkar.save
250
250
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 3}]
251
251
  @community_1.save
252
252
  @community_1.admin_level_of(@salkar).should == 3
@@ -257,8 +257,6 @@ describe "Community" do
257
257
  end
258
258
 
259
259
  it "admin should be added" do
260
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 0}]
261
- @salkar.save
262
260
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}]
263
261
  @community_1.save
264
262
  @community_1.add_user :user => @salkar
@@ -278,8 +276,6 @@ describe "Community" do
278
276
  expect { @community_1.add_admin(:user => @salkar, :admin => @talisman) }.to raise_error
279
277
  expect { @community_1.add_admin(:user => "@salkar", :admin => "@talisman") }.to raise_error
280
278
 
281
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 0}]
282
- @salkar.save
283
279
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}]
284
280
  @community_1.save
285
281
  @community_1.add_user :user => @salkar
@@ -291,12 +287,9 @@ describe "Community" do
291
287
  @community_1.reload
292
288
  @salkar.reload
293
289
  ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1
294
- ActiveSupport::JSON.decode(@salkar.admin_of).size.should == 1
295
290
  end
296
291
 
297
292
  it "admin should be removed" do
298
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 0}]
299
- @salkar.save
300
293
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}]
301
294
  @community_1.save
302
295
  @community_1.add_user :user => @salkar
@@ -314,7 +307,6 @@ describe "Community" do
314
307
  @community_1.include_admin?(@salkar).should == true
315
308
  @community_1.include_admin?(@morozovm).should == false
316
309
  ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1
317
- ActiveSupport::JSON.decode(@morozovm.admin_of).size.should == 0
318
310
 
319
311
  @community_1.add_admin :admin => @salkar, :user => @morozovm
320
312
  @community_1.reload
@@ -331,8 +323,6 @@ describe "Community" do
331
323
  expect { @community_1.remove_admin :admin => "@salkar", :user => "@morozovm" }.to raise_error
332
324
  expect { @community_1.remove_admin :user => @morozovm }.to raise_error
333
325
 
334
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 0}]
335
- @salkar.save
336
326
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}]
337
327
  @community_1.save
338
328
  @community_1.add_user :user => @salkar
@@ -412,7 +402,6 @@ describe "Community" do
412
402
  @salkar.communities_row.size.should == 0
413
403
  @talisman.communities_row.size.should == 0
414
404
  @morozovm.communities_row.size.should == 0
415
- ActiveSupport::JSON.decode(@talisman.admin_of).size.should == 0
416
405
  end
417
406
 
418
407
  it "post should be added to community blogline and user's timeline" do
@@ -560,17 +549,17 @@ describe "Community" do
560
549
  it "user should join community" do
561
550
  users_ids = ActiveSupport::JSON.decode @community_1.users_ids
562
551
  users_ids.size.should == 1
563
- communities_ids = ActiveSupport::JSON.decode @salkar.communities_ids
564
- communities_ids.size.should == 0
552
+ communities_info = ActiveSupport::JSON.decode @salkar.communities_info
553
+ communities_info.size.should == 0
565
554
  @salkar.join @community_1
566
555
  @community_1.reload
567
556
  @salkar.reload
568
557
  users_ids = ActiveSupport::JSON.decode @community_1.users_ids
569
558
  users_ids.size.should == 2
570
559
  users_ids[1].should == @salkar.id
571
- communities_ids = ActiveSupport::JSON.decode @salkar.communities_ids
572
- communities_ids.size.should == 1
573
- communities_ids[0].should == @community_1.id
560
+ communities_info = ActiveSupport::JSON.decode @salkar.communities_info
561
+ communities_info.size.should == 1
562
+ communities_info[0].should == {"c_id"=>@community_1.id, "a"=>"w"}
574
563
  end
575
564
 
576
565
  it "user should leave community" do
@@ -583,7 +572,6 @@ describe "Community" do
583
572
  @salkar.reload
584
573
  @community_1.include_user?(@salkar).should == false
585
574
  ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1
586
- ActiveSupport::JSON.decode(@salkar.admin_of).size.should == 0
587
575
  end
588
576
 
589
577
  it "user should be kicked from community" do
@@ -597,7 +585,6 @@ describe "Community" do
597
585
  @salkar.reload
598
586
  @community_1.include_user?(@salkar).should == false
599
587
  ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1
600
- ActiveSupport::JSON.decode(@salkar.admin_of).size.should == 0
601
588
  end
602
589
 
603
590
  it "post should be sended to community" do
@@ -647,8 +634,6 @@ describe "Community" do
647
634
  end
648
635
 
649
636
  it "admin permissions should be granted" do
650
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 0}]
651
- @salkar.save
652
637
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}]
653
638
  @community_1.save
654
639
  @community_1.add_user :user => @salkar
@@ -664,8 +649,6 @@ describe "Community" do
664
649
  end
665
650
 
666
651
  it "admin permissions should be revoked" do
667
- @salkar.admin_of = ActiveSupport::JSON.encode [{:community_id => @community_1.id, :admin_level => 0}]
668
- @salkar.save
669
652
  @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}]
670
653
  @community_1.save
671
654
  @community_1.add_user :user => @salkar
@@ -683,7 +666,896 @@ describe "Community" do
683
666
  @community_1.include_admin?(@salkar).should == true
684
667
  @community_1.include_admin?(@morozovm).should == false
685
668
  ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1
686
- ActiveSupport::JSON.decode(@morozovm.admin_of).size.should == 0
669
+ end
670
+
671
+ it "community row should be returned for user" do
672
+ @community_2 = Community.create :name => "Community_1", :owner_id => @talisman.id
673
+ @community_3 = Community.create :name => "Community_1", :owner_id => @talisman.id
674
+ @talisman.reload
675
+ @talisman.communities_row.should == [@community_1.id, @community_2.id, @community_3.id]
676
+ end
677
+
678
+ it "admin should be added to community users in open community" do
679
+ @community_1.reload
680
+ @talisman.reload
681
+ @community_1.include_user?(@talisman).should == true
682
+ @community_1.include_admin?(@talisman).should == true
683
+ end
684
+
685
+ it "private community with default W access should be created" do
686
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
687
+ @private_community.reload
688
+ @morozovm.reload
689
+ @private_community.public.should == false
690
+ @private_community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]"
691
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
692
+ @private_community.users_ids.should == "[#{@morozovm.id}]"
693
+ ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id"=>@private_community.id, "a"=>"w"}]
694
+ end
695
+
696
+ it "private community with default R access should be created" do
697
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
698
+ @private_community.default_user_access = 'r'
699
+ @private_community.save
700
+ @private_community.reload
701
+ @morozovm.reload
702
+ @private_community.public.should == false
703
+ @private_community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]"
704
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
705
+ @private_community.users_ids.should == "[#{@morozovm.id}]"
706
+ ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id"=>@private_community.id, "a"=>"w"}]
707
+ end
708
+
709
+ it "public community with default W access should be created" do
710
+ @w_community = Community.create :name => "Community", :owner_id => @morozovm.id
711
+ @w_community.reload
712
+ @morozovm.reload
713
+ @w_community.public.should == true
714
+ @w_community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]"
715
+ @w_community.writers_ids.should == "[#{@morozovm.id}]"
716
+ @w_community.users_ids.should == "[#{@morozovm.id}]"
717
+ ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id"=>@w_community.id, "a"=>"w"}]
718
+ end
719
+
720
+ it "public community with default R access should be created" do
721
+ @community = Community.create :name => "Community", :owner_id => @morozovm.id
722
+ @community.default_user_access = 'r'
723
+ @community.save
724
+ @community.reload
725
+ @morozovm.reload
726
+ @community.public.should == true
727
+ @community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]"
728
+ @community.writers_ids.should == "[#{@morozovm.id}]"
729
+ @community.users_ids.should == "[#{@morozovm.id}]"
730
+ ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id" => @community.id, "a" => "w"}]
731
+ end
732
+
733
+ it "added to public community with default W access user should have W access" do
734
+ @w_community = Community.create :name => "Community", :owner_id => @morozovm.id
735
+ @w_community.reload
736
+ @morozovm.reload
737
+ @w_community.add_user :user => @salkar
738
+ @w_community.reload
739
+ @salkar.reload
740
+ @w_community.include_user?(@salkar).should == true
741
+ ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @w_community.id, "a" => "w"}]
742
+ ActiveSupport::JSON.decode(@w_community.users_ids).should == [@morozovm.id, @salkar.id]
743
+ ActiveSupport::JSON.decode(@w_community.writers_ids).should == [@morozovm.id, @salkar.id]
744
+ end
745
+
746
+ it "added to public community with default R access user should have R access" do
747
+ @community = Community.create :name => "Community", :owner_id => @morozovm.id
748
+ @community.default_user_access = 'r'
749
+ @community.save
750
+ @community.reload
751
+ @morozovm.reload
752
+ @community.add_user :user => @salkar
753
+ @community.reload
754
+ @salkar.reload
755
+ @community.include_user?(@salkar).should == true
756
+ ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @community.id, "a" => "r"}]
757
+ ActiveSupport::JSON.decode(@community.users_ids).should == [@morozovm.id, @salkar.id]
758
+ ActiveSupport::JSON.decode(@community.writers_ids).should == [@morozovm.id]
759
+ end
760
+
761
+ it "added to private community with default W access user should have W access" do
762
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
763
+ @private_community.create_invitation_request @salkar
764
+ @private_community.reload
765
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
766
+ @salkar.reload
767
+ @private_community.reload
768
+ @private_community.include_user?(@salkar).should == true
769
+ @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
770
+ @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
771
+ @salkar.communities_row.should == [@private_community.id]
772
+ ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @private_community.id, "a" => "w"}]
773
+ end
774
+
775
+ it "added to private community with default R access user should have R access" do
776
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
777
+ @private_community.default_user_access = 'r'
778
+ @private_community.save
779
+ @private_community.create_invitation_request @salkar
780
+ @private_community.reload
781
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
782
+ @salkar.reload
783
+ @private_community.reload
784
+ @private_community.include_user?(@salkar).should == true
785
+ @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
786
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
787
+ @salkar.communities_row.should == [@private_community.id]
788
+ ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @private_community.id, "a" => "r"}]
789
+ end
790
+
791
+ it "request invitation should be created (include_invitation_request?)" do
792
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
793
+ @private_community.create_invitation_request @salkar
794
+ @private_community.reload
795
+ @private_community.invitations_uids.should == "[#{@salkar.id}]"
796
+ @private_community.include_invitation_request?(@salkar).should == true
797
+ end
798
+
799
+ it "request invitation should be created (include_invitation_request?)" do
800
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
801
+ @private_community.reload
802
+ @private_community.include_invitation_request?(@salkar).should == false
803
+ @private_community.create_invitation_request @talisman
804
+ @private_community.reload
805
+ @private_community.include_invitation_request?(@salkar).should == false
806
+ end
807
+
808
+ it "error should be excepted on try to check invitation request for public community" do
809
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
810
+ @public_community.reload
811
+ expect { @public_community.include_invitation_request?(@salkar) }.to raise_error
812
+ end
813
+
814
+ it "request invitation should be created" do
815
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
816
+ @private_community.create_invitation_request @salkar
817
+ @private_community.reload
818
+ @private_community.invitations_uids.should == "[#{@salkar.id}]"
819
+ end
820
+
821
+ it "request invitation should not be created" do
822
+ expect { @community_1.create_invitation_request(@salkar) }.to raise_error
823
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
824
+ @private_community.banned_ids = "[#{@talisman.id}]"
825
+ @private_community.save
826
+ expect { @private_community.create_invitation_request(@talisman) }.to raise_error
827
+ @private_community.create_invitation_request(@salkar)
828
+ expect { @private_community.create_invitation_request(@salkar) }.to raise_error
829
+ end
830
+
831
+ it "user should not be added to public community cause he is banned" do
832
+ @community_1.banned_ids = "[#{@morozovm.id}]"
833
+ @community_1.save
834
+ expect { @morozovm.join @community_1 }.to raise_error
835
+ end
836
+
837
+ it "error should be raised on trying to add to community user who already added to it" do
838
+ @salkar.join @community_1
839
+ expect { @salkar.join @community_1 }.to raise_error
840
+ end
841
+
842
+ it "invitation request should be rejected" do
843
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
844
+ @private_community.create_invitation_request(@salkar)
845
+ @private_community.reload
846
+ @private_community.include_invitation_request?(@salkar).should == true
847
+ @private_community.reject_invitation_request :user => @salkar, :admin => @morozovm
848
+ @private_community.reload
849
+ @private_community.include_invitation_request?(@salkar).should == false
850
+ end
851
+
852
+ it "invitation request should not be rejected" do
853
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
854
+ @private_community.create_invitation_request(@salkar)
855
+ @private_community.add_user :user => @talisman #only for test
856
+ @private_community.reload
857
+ expect { @private_community.reject_invitation_request :user => @spy, :admin => @morozovm }.to raise_error
858
+ expect { @private_community.reject_invitation_request :user => @salkar }.to raise_error
859
+ expect { @private_community.reject_invitation_request :admin => @morozovm }.to raise_error
860
+ expect { @private_community.reject_invitation_request :user => @salkar, :admin => @talisman }.to raise_error
861
+ end
862
+
863
+ it "invitation request should be accepted" do
864
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
865
+ @private_community.create_invitation_request @salkar
866
+ @private_community.reload
867
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
868
+ @salkar.reload
869
+ @private_community.reload
870
+ @private_community.include_user?(@salkar).should == true
871
+ @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
872
+ @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
873
+ @salkar.communities_row.should == [@private_community.id]
874
+ end
875
+
876
+ it "invitation request should not be accepted" do
877
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
878
+ @private_community.create_invitation_request @salkar
879
+ @private_community.add_user :user => @talisman #only for test
880
+ @private_community.reload
881
+
882
+ expect { @private_community.accept_invitation_request :user => @spy, :admin => @morozovm }.to raise_error
883
+ expect { @private_community.accept_invitation_request :user => @salkar }.to raise_error
884
+ expect { @private_community.accept_invitation_request :admin => @morozovm }.to raise_error
885
+ expect { @private_community.accept_invitation_request :user => @salkar, :admin => @talisman }.to raise_error
886
+ @private_community.add_user :user => @salkar #only for test
887
+ expect { @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm }.to raise_error
888
+ end
889
+
890
+ it "user should be removed from private community" do
891
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
892
+ @private_community.add_user :user => @salkar #only for test
893
+ @private_community.reload
894
+ @salkar.reload
895
+
896
+ @private_community.include_user?(@salkar).should == true
897
+ @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
898
+ @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
899
+ @salkar.communities_row.should == [@private_community.id]
900
+
901
+ @private_community.remove_user :admin => @morozovm, :user => @salkar
902
+ @private_community.reload
903
+ @salkar.reload
904
+
905
+ @private_community.include_user?(@salkar).should == false
906
+ @private_community.users_ids.should == "[#{@morozovm.id}]"
907
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
908
+ @salkar.communities_row.should == []
909
+ end
910
+
911
+ it "admin should be removed from private community" do
912
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
913
+ @private_community.add_user :user => @salkar #only for test
914
+ @private_community.add_admin :user => @salkar, :admin => @morozovm
915
+ @private_community.reload
916
+ @salkar.reload
917
+
918
+ @private_community.include_user?(@salkar).should == true
919
+ @private_community.include_admin?(@salkar).should == true
920
+ @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
921
+ @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
922
+ ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should_not == nil
923
+ @salkar.communities_row.should == [@private_community.id]
924
+
925
+ @private_community.remove_user :admin => @morozovm, :user => @salkar
926
+ @private_community.reload
927
+ @salkar.reload
928
+
929
+ @private_community.include_user?(@salkar).should == false
930
+ ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil
931
+ @private_community.users_ids.should == "[#{@morozovm.id}]"
932
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
933
+ @salkar.communities_row.should == []
934
+ end
935
+
936
+ it "user should leave private community" do
937
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
938
+ @private_community.create_invitation_request @salkar
939
+ @private_community.reload
940
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
941
+ @salkar.reload
942
+ @private_community.reload
943
+
944
+ @salkar.leave @private_community
945
+ @salkar.reload
946
+ @private_community.reload
947
+
948
+ @private_community.include_user?(@salkar).should == false
949
+ ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil
950
+ @private_community.users_ids.should == "[#{@morozovm.id}]"
951
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
952
+ @salkar.communities_row.should == []
953
+ end
954
+
955
+ it "user should be kicked from private community" do
956
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
957
+ @private_community.create_invitation_request @salkar
958
+ @private_community.reload
959
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
960
+ @salkar.reload
961
+ @private_community.reload
962
+
963
+ @morozovm.kick :user => @salkar, :from_community => @private_community
964
+ @salkar.reload
965
+ @private_community.reload
966
+
967
+ @private_community.include_user?(@salkar).should == false
968
+ ActiveSupport::JSON.decode(@private_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should == nil
969
+ @private_community.users_ids.should == "[#{@morozovm.id}]"
970
+ @private_community.writers_ids.should == "[#{@morozovm.id}]"
971
+ @salkar.communities_row.should == []
972
+ end
973
+
974
+ it "user should not join private community" do
975
+ @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false
976
+ expect { @salkar.join @private_community }.to raise_error
977
+ end
978
+
979
+ it "user info should be deleted from community with W access if user is removed" do
980
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
981
+ @salkar.join @public_community
982
+ @public_community.reload
983
+ @morozovm.reload
984
+ @public_community.add_admin :user => @salkar, :admin => @morozovm
985
+ @salkar.reload
986
+ @public_community.reload
987
+
988
+ @public_community.include_user?(@salkar).should == true
989
+ @public_community.include_admin?(@salkar).should == true
990
+ @public_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
991
+ @public_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]"
992
+ ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should_not == nil
993
+ @salkar.communities_row.should == [@public_community.id]
994
+
995
+ @morozovm.kick :user => @salkar, :from_community => @public_community
996
+ @salkar.reload
997
+ @public_community.reload
998
+
999
+ @public_community.include_user?(@salkar).should == false
1000
+ ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should == nil
1001
+ @public_community.users_ids.should == "[#{@morozovm.id}]"
1002
+ @public_community.writers_ids.should == "[#{@morozovm.id}]"
1003
+ @salkar.communities_row.should == []
1004
+ end
1005
+
1006
+ it "user should be muted" do
1007
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1008
+ @salkar.join @public_community
1009
+ @salkar.reload
1010
+ @public_community.reload
1011
+ @morozovm.reload
1012
+
1013
+ @public_community.include_muted_user?(@salkar).should == false
1014
+ @public_community.mute_user :user => @salkar, :admin => @morozovm
1015
+ @public_community.reload
1016
+ @public_community.include_muted_user?(@salkar).should == true
1017
+
1018
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1019
+ @private_community.create_invitation_request @salkar
1020
+ @private_community.reload
1021
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1022
+ @salkar.reload
1023
+ @private_community.reload
1024
+
1025
+ @private_community.include_muted_user?(@salkar).should == false
1026
+ @private_community.mute_user :user => @salkar, :admin => @morozovm
1027
+ @private_community.reload
1028
+ @private_community.include_muted_user?(@salkar).should == true
1029
+ end
1030
+
1031
+ it "user should not be muted" do
1032
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1033
+ @talisman.join @public_community
1034
+ @salkar.join @public_community
1035
+ @salkar.reload
1036
+ @public_community.reload
1037
+ @morozovm.reload
1038
+ @talisman.reload
1039
+
1040
+ expect { @public_community.mute_user :user => @spy, :admin => @morozovm }.to raise_error
1041
+ expect { @public_community.mute_user :user => @salkar }.to raise_error
1042
+ expect { @public_community.mute_user :admin => @morozovm }.to raise_error
1043
+ expect { @public_community.mute_user :user => @salkar, :admin => @talisman }.to raise_error
1044
+ expect { @public_community.mute_user :user => @morozovm, :admin => @morozovm }.to raise_error
1045
+ @public_community.add_admin :user => @talisman, :admin => @morozovm
1046
+ expect { @public_community.mute_user :user => @morozovm, :admin => @talisman }.to raise_error
1047
+ @public_community.add_admin :user => @salkar, :admin => @morozovm
1048
+ expect { @public_community.mute_user :user => @salkar, :admin => @talisman }.to raise_error
1049
+ @public_community.mute_user :user => @salkar, :admin => @morozovm
1050
+ expect { @public_community.mute_user :user => @salkar, :admin => @morozovm }.to raise_error
1051
+ end
1052
+
1053
+ it "user should be unmuted" do
1054
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1055
+ @salkar.join @public_community
1056
+ @salkar.reload
1057
+ @public_community.reload
1058
+ @morozovm.reload
1059
+
1060
+ @public_community.include_muted_user?(@salkar).should == false
1061
+ @public_community.mute_user :user => @salkar, :admin => @morozovm
1062
+ @public_community.reload
1063
+ @public_community.include_muted_user?(@salkar).should == true
1064
+ @public_community.unmute_user :user => @salkar, :admin => @morozovm
1065
+ @public_community.reload
1066
+ @public_community.include_muted_user?(@salkar).should == false
1067
+
1068
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1069
+ @private_community.create_invitation_request @salkar
1070
+ @private_community.reload
1071
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1072
+ @salkar.reload
1073
+ @private_community.reload
1074
+
1075
+ @private_community.include_muted_user?(@salkar).should == false
1076
+ @private_community.mute_user :user => @salkar, :admin => @morozovm
1077
+ @private_community.reload
1078
+ @private_community.include_muted_user?(@salkar).should == true
1079
+ @private_community.unmute_user :user => @salkar, :admin => @morozovm
1080
+ @private_community.reload
1081
+ @private_community.include_muted_user?(@salkar).should == false
1082
+ end
1083
+
1084
+ it "user should not be unmuted" do
1085
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1086
+ @private_community.create_invitation_request @talisman
1087
+ @private_community.reload
1088
+ @private_community.accept_invitation_request :user => @talisman, :admin => @morozovm
1089
+ @talisman.reload
1090
+ @private_community.create_invitation_request @salkar
1091
+ @private_community.reload
1092
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1093
+ @private_community.mute_user :user => @salkar, :admin => @morozovm
1094
+ @salkar.reload
1095
+ @private_community.reload
1096
+ @morozovm.reload
1097
+ @talisman.reload
1098
+
1099
+ expect { @private_community.unmute_user :user => @spy, :admin => @morozovm }.to raise_error
1100
+
1101
+ expect { @private_community.unmute_user :user => @salkar }.to raise_error
1102
+ expect { @private_community.unmute_user :admin => @morozovm }.to raise_error
1103
+ expect { @private_community.unmute_user :user => @salkar, :admin => @talisman }.to raise_error
1104
+ end
1105
+
1106
+ it "user should be unmuted when he is become admin" do
1107
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1108
+ @salkar.join @public_community
1109
+ @salkar.reload
1110
+ @public_community.reload
1111
+ @morozovm.reload
1112
+
1113
+ @public_community.include_muted_user?(@salkar).should == false
1114
+ @public_community.mute_user :user => @salkar, :admin => @morozovm
1115
+ @public_community.reload
1116
+ @public_community.include_muted_user?(@salkar).should == true
1117
+ @public_community.add_admin :user => @salkar, :admin => @morozovm
1118
+ @public_community.reload
1119
+ @public_community.include_muted_user?(@salkar).should == false
1120
+
1121
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1122
+ @private_community.create_invitation_request @salkar
1123
+ @private_community.reload
1124
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1125
+ @salkar.reload
1126
+ @private_community.reload
1127
+
1128
+ @private_community.include_muted_user?(@salkar).should == false
1129
+ @private_community.mute_user :user => @salkar, :admin => @morozovm
1130
+ @private_community.reload
1131
+ @private_community.include_muted_user?(@salkar).should == true
1132
+ @private_community.add_admin :user => @salkar, :admin => @morozovm
1133
+ @private_community.reload
1134
+ @private_community.include_muted_user?(@salkar).should == false
1135
+ end
1136
+
1137
+ it "user should be banned" do
1138
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1139
+ @salkar.join @public_community
1140
+ @salkar.reload
1141
+ @public_community.reload
1142
+ @morozovm.reload
1143
+
1144
+ @public_community.include_banned_user?(@salkar).should == false
1145
+ @public_community.ban_user :user => @salkar, :admin => @morozovm
1146
+ @public_community.reload
1147
+ @public_community.include_banned_user?(@salkar).should == true
1148
+ @public_community.include_user?(@salkar).should == false
1149
+
1150
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1151
+ @private_community.create_invitation_request @salkar
1152
+ @private_community.reload
1153
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1154
+ @salkar.reload
1155
+ @private_community.reload
1156
+
1157
+ @private_community.include_banned_user?(@salkar).should == false
1158
+ @private_community.ban_user :user => @salkar, :admin => @morozovm
1159
+ @private_community.reload
1160
+ @private_community.include_banned_user?(@salkar).should == true
1161
+ @private_community.include_user?(@salkar).should == false
1162
+ end
1163
+
1164
+ it "admin should be banned" do
1165
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1166
+ @salkar.join @public_community
1167
+ @public_community.add_admin :user => @salkar, :admin => @morozovm
1168
+ @salkar.reload
1169
+ @public_community.reload
1170
+ @morozovm.reload
1171
+
1172
+ ActiveSupport::JSON.decode(@public_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should_not == nil
1173
+ @public_community.include_banned_user?(@salkar).should == false
1174
+ @public_community.ban_user :user => @salkar, :admin => @morozovm
1175
+ @public_community.reload
1176
+ @public_community.include_banned_user?(@salkar).should == true
1177
+ @public_community.include_user?(@salkar).should == false
1178
+ ActiveSupport::JSON.decode(@public_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil
1179
+
1180
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1181
+ @private_community.create_invitation_request @salkar
1182
+ @private_community.reload
1183
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1184
+ @private_community.add_admin :user => @salkar, :admin => @morozovm
1185
+ @salkar.reload
1186
+ @private_community.reload
1187
+
1188
+ ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should_not == nil
1189
+ @private_community.include_banned_user?(@salkar).should == false
1190
+ @private_community.ban_user :user => @salkar, :admin => @morozovm
1191
+ @private_community.reload
1192
+ @private_community.include_banned_user?(@salkar).should == true
1193
+ @private_community.include_user?(@salkar).should == false
1194
+ ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil
1195
+ end
1196
+
1197
+ it "user with request invitation should be banned" do
1198
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1199
+ @private_community.create_invitation_request @salkar
1200
+ @private_community.reload
1201
+ @private_community.include_banned_user?(@salkar).should == false
1202
+ @private_community.ban_user :user => @salkar, :admin => @morozovm
1203
+ @private_community.reload
1204
+ @private_community.include_banned_user?(@salkar).should == true
1205
+ @private_community.include_user?(@salkar).should == false
1206
+ end
1207
+
1208
+ it "user should not be banned" do
1209
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1210
+ @talisman.join @public_community
1211
+ @salkar.join @public_community
1212
+ @salkar.reload
1213
+ @public_community.reload
1214
+ @morozovm.reload
1215
+ @talisman.reload
1216
+
1217
+ expect { @public_community.ban_user :user => @spy, :admin => @morozovm }.to raise_error
1218
+ expect { @public_community.ban_user :user => @salkar }.to raise_error
1219
+ expect { @public_community.ban_user :admin => @morozovm }.to raise_error
1220
+ expect { @public_community.ban_user :user => @salkar, :admin => @talisman }.to raise_error
1221
+ expect { @public_community.ban_user :user => @morozovm, :admin => @morozovm }.to raise_error
1222
+ @public_community.add_admin :user => @talisman, :admin => @morozovm
1223
+ expect { @public_community.ban_user :user => @morozovm, :admin => @talisman }.to raise_error
1224
+ @public_community.add_admin :user => @salkar, :admin => @morozovm
1225
+ expect { @public_community.ban_user :user => @salkar, :admin => @talisman }.to raise_error
1226
+ @public_community.ban_user :user => @salkar, :admin => @morozovm
1227
+ expect { @public_community.ban_user :user => @salkar, :admin => @morozovm }.to raise_error
1228
+ end
1229
+
1230
+ it "user should be unbanned" do
1231
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1232
+ @salkar.join @public_community
1233
+ @salkar.reload
1234
+ @public_community.reload
1235
+ @morozovm.reload
1236
+
1237
+ @public_community.include_banned_user?(@salkar).should == false
1238
+ @public_community.ban_user :user => @salkar, :admin => @morozovm
1239
+ @public_community.reload
1240
+ @public_community.include_banned_user?(@salkar).should == true
1241
+ @public_community.unban_user :user => @salkar, :admin => @morozovm
1242
+ @public_community.reload
1243
+ @public_community.include_banned_user?(@salkar).should == false
1244
+
1245
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1246
+ @private_community.create_invitation_request @salkar
1247
+ @private_community.reload
1248
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1249
+ @salkar.reload
1250
+ @private_community.reload
1251
+
1252
+ @private_community.include_banned_user?(@salkar).should == false
1253
+ @private_community.ban_user :user => @salkar, :admin => @morozovm
1254
+ @private_community.reload
1255
+ @private_community.include_banned_user?(@salkar).should == true
1256
+ @private_community.unban_user :user => @salkar, :admin => @morozovm
1257
+ @private_community.reload
1258
+ @private_community.include_banned_user?(@salkar).should == false
1259
+ end
1260
+
1261
+ it "user should not be unbanned" do
1262
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1263
+ @private_community.create_invitation_request @talisman
1264
+ @private_community.reload
1265
+ @private_community.accept_invitation_request :user => @talisman, :admin => @morozovm
1266
+ @talisman.reload
1267
+ @private_community.create_invitation_request @salkar
1268
+ @private_community.reload
1269
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1270
+ @private_community.ban_user :user => @salkar, :admin => @morozovm
1271
+ @salkar.reload
1272
+ @private_community.reload
1273
+ @morozovm.reload
1274
+ @talisman.reload
1275
+
1276
+ expect { @private_community.unban_user :user => @spy, :admin => @morozovm }.to raise_error
1277
+
1278
+ expect { @private_community.unban_user :user => @salkar }.to raise_error
1279
+ expect { @private_community.unban_user :admin => @morozovm }.to raise_error
1280
+ expect { @private_community.unban_user :user => @salkar, :admin => @talisman }.to raise_error
1281
+ end
1282
+
1283
+ it "admin should ban another user" do
1284
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1285
+ @salkar.join @public_community
1286
+ @public_community.add_admin :user => @salkar, :admin => @morozovm
1287
+ @salkar.reload
1288
+ @public_community.reload
1289
+ @morozovm.reload
1290
+
1291
+ ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should_not == nil
1292
+ @public_community.include_banned_user?(@salkar).should == false
1293
+ @morozovm.ban :user => @salkar, :in_community => @public_community
1294
+ @public_community.reload
1295
+ @public_community.include_banned_user?(@salkar).should == true
1296
+ @public_community.include_user?(@salkar).should == false
1297
+ ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should == nil
1298
+ end
1299
+
1300
+ it "user should unban another user" do
1301
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1302
+ @private_community.create_invitation_request @salkar
1303
+ @private_community.reload
1304
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1305
+ @salkar.reload
1306
+ @private_community.reload
1307
+
1308
+ @private_community.include_banned_user?(@salkar).should == false
1309
+ @private_community.ban_user :user => @salkar, :admin => @morozovm
1310
+ @private_community.reload
1311
+ @private_community.include_banned_user?(@salkar).should == true
1312
+ @morozovm.unban :user => @salkar, :in_community => @private_community
1313
+ @private_community.reload
1314
+ @private_community.include_banned_user?(@salkar).should == false
1315
+ end
1316
+
1317
+ it "user should muted another user" do
1318
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1319
+ @salkar.join @public_community
1320
+ @salkar.reload
1321
+ @public_community.reload
1322
+ @morozovm.reload
1323
+
1324
+ @public_community.include_muted_user?(@salkar).should == false
1325
+ @morozovm.mute :user => @salkar, :in_community => @public_community
1326
+ @public_community.reload
1327
+ @public_community.include_muted_user?(@salkar).should == true
1328
+ end
1329
+
1330
+ it "user should unmute another user" do
1331
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1332
+ @private_community.create_invitation_request @salkar
1333
+ @private_community.reload
1334
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1335
+ @salkar.reload
1336
+ @private_community.reload
1337
+
1338
+ @private_community.include_muted_user?(@salkar).should == false
1339
+ @private_community.mute_user :user => @salkar, :admin => @morozovm
1340
+ @private_community.reload
1341
+ @private_community.include_muted_user?(@salkar).should == true
1342
+ @morozovm.unmute :user => @salkar, :in_community => @private_community
1343
+ @private_community.reload
1344
+ @private_community.include_muted_user?(@salkar).should == false
1345
+ end
1346
+
1347
+ it "muted user should not be able to add post to community" do
1348
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1349
+ @salkar.join @public_community
1350
+ @salkar.reload
1351
+ @public_community.reload
1352
+ @morozovm.reload
1353
+
1354
+ @public_community.include_muted_user?(@salkar).should == false
1355
+ @public_community.mute_user :user => @salkar, :admin => @morozovm
1356
+ @public_community.reload
1357
+ @public_community.include_muted_user?(@salkar).should == true
1358
+ expect { @public_community.add_post :user => @salkar, :post => @salkar_post }.to raise_error
1359
+
1360
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1361
+ @private_community.create_invitation_request @salkar
1362
+ @private_community.reload
1363
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1364
+ @salkar.reload
1365
+ @private_community.reload
1366
+
1367
+ @private_community.include_muted_user?(@salkar).should == false
1368
+ @private_community.mute_user :user => @salkar, :admin => @morozovm
1369
+ @private_community.reload
1370
+ @private_community.include_muted_user?(@salkar).should == true
1371
+ expect { @private_community.add_post :user => @salkar, :post => @salkar_post }.to raise_error
1372
+ end
1373
+
1374
+ it "user should be writer in community (include_writer?)" do
1375
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1376
+ @salkar.join @public_community
1377
+ @salkar.reload
1378
+ @public_community.reload
1379
+ @morozovm.reload
1380
+
1381
+ @public_community.include_writer?(@morozovm).should == true
1382
+ @public_community.include_writer?(@salkar).should == true
1383
+
1384
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1385
+ @private_community.create_invitation_request @salkar
1386
+ @private_community.reload
1387
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1388
+ @salkar.reload
1389
+ @private_community.reload
1390
+
1391
+ @private_community.include_writer?(@morozovm).should == true
1392
+ @private_community.include_writer?(@salkar).should == true
1393
+ end
1394
+
1395
+ it "user should not be writer in community (include_writer?)" do
1396
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1397
+ @public_community.default_user_access = 'r'
1398
+ @public_community.save
1399
+ @salkar.join @public_community
1400
+ @salkar.reload
1401
+ @public_community.reload
1402
+ @morozovm.reload
1403
+
1404
+ @public_community.include_writer?(@morozovm).should == true
1405
+ @public_community.include_writer?(@salkar).should == false
1406
+ @public_community.include_writer?(@talisman).should == false
1407
+
1408
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1409
+ @private_community.default_user_access = 'r'
1410
+ @private_community.save
1411
+ @private_community.create_invitation_request @salkar
1412
+ @private_community.reload
1413
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1414
+ @salkar.reload
1415
+ @private_community.reload
1416
+
1417
+ @private_community.include_writer?(@morozovm).should == true
1418
+ @private_community.include_writer?(@salkar).should == false
1419
+ @private_community.include_writer?(@talisman).should == false
1420
+ end
1421
+
1422
+ it "user should be able to send post to community (can_send_post_to_community?)" do
1423
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1424
+ @salkar.join @public_community
1425
+ @salkar.reload
1426
+ @public_community.reload
1427
+ @morozovm.reload
1428
+
1429
+ @morozovm.can_send_post_to_community?(@public_community).should == true
1430
+ @salkar.can_send_post_to_community?(@public_community).should == true
1431
+
1432
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1433
+ @private_community.create_invitation_request @salkar
1434
+ @private_community.reload
1435
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1436
+ @salkar.reload
1437
+ @morozovm.reload
1438
+ @private_community.reload
1439
+
1440
+ @morozovm.can_send_post_to_community?(@private_community).should == true
1441
+ @salkar.can_send_post_to_community?(@private_community).should == true
1442
+ end
1443
+
1444
+ it "user should be able to send post to community (can_send_post_to_community?)" do
1445
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1446
+ @salkar.join @public_community
1447
+ @salkar.reload
1448
+ @public_community.reload
1449
+ @morozovm.reload
1450
+
1451
+ @morozovm.mute :user => @salkar, :in_community => @public_community
1452
+ @public_community.reload
1453
+ @salkar.can_send_post_to_community?(@public_community).should == false
1454
+ @talisman.can_send_post_to_community?(@public_community).should == false
1455
+ @public_community.default_user_access = 'r'
1456
+ @public_community.save
1457
+ @talisman.join @public_community
1458
+ @public_community.reload
1459
+ @talisman.reload
1460
+ @talisman.can_send_post_to_community?(@public_community).should == false
1461
+
1462
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1463
+ @private_community.default_user_access = 'r'
1464
+ @private_community.save
1465
+ @private_community.create_invitation_request @salkar
1466
+ @private_community.reload
1467
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1468
+ @salkar.reload
1469
+ @private_community.reload
1470
+
1471
+ @morozovm.mute :user => @salkar, :in_community => @private_community
1472
+ @private_community.reload
1473
+ @salkar.can_send_post_to_community?(@private_community).should == false
1474
+ @talisman.can_send_post_to_community?(@private_community).should == false
1475
+ @private_community.default_user_access = 'r'
1476
+ @private_community.save
1477
+ @private_community.create_invitation_request @talisman
1478
+ @private_community.reload
1479
+ @private_community.accept_invitation_request :user => @talisman, :admin => @morozovm
1480
+ @talisman.reload
1481
+ @private_community.reload
1482
+ @talisman.can_send_post_to_community?(@private_community).should == false
1483
+ end
1484
+
1485
+ it "post should be sended to community" do
1486
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1487
+ @salkar.join @public_community
1488
+ @salkar.reload
1489
+ @public_community.reload
1490
+ @salkar.send_post_to_community :to_community => @public_community, :post => @salkar_post
1491
+ @salkar_post.communities_row.should == [@public_community.id]
1492
+
1493
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1494
+ @private_community.create_invitation_request @salkar
1495
+ @private_community.reload
1496
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1497
+ @salkar.reload
1498
+ @private_community.reload
1499
+ @salkar.send_post_to_community :to_community => @private_community, :post => @salkar_post
1500
+ @salkar_post.communities_row.should == [@public_community.id, @private_community.id]
1501
+ end
1502
+
1503
+ it "post should not be sended to community" do
1504
+ @public_community_r = Community.create :name => "Community", :owner_id => @morozovm.id
1505
+ @talisman.join @public_community_r
1506
+ @public_community_r.default_user_access = 'r'
1507
+ @public_community_r.save
1508
+ @salkar.join @public_community_r
1509
+ @salkar.reload
1510
+ @public_community_r.reload
1511
+ expect {@salkar.send_post_to_community :to_community => @public_community_r, :post => @salkar_post}.to raise_error
1512
+ @salkar_post.communities_row.should == []
1513
+
1514
+ @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false
1515
+
1516
+ @private_community.create_invitation_request @talisman
1517
+ @private_community.reload
1518
+ @private_community.accept_invitation_request :user => @talisman, :admin => @morozovm
1519
+ @salkar.reload
1520
+ @private_community.reload
1521
+
1522
+ @private_community.default_user_access = 'r'
1523
+ @private_community.save
1524
+ @private_community.create_invitation_request @salkar
1525
+ @private_community.reload
1526
+ @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm
1527
+ @salkar.reload
1528
+ @private_community.reload
1529
+ expect {@salkar.send_post_to_community :to_community => @private_community, :post => @salkar_post}.to raise_error
1530
+ @salkar_post.communities_row.should == []
1531
+
1532
+ @spy_post = @spy.posts.create :body => "spy_post_test_body"
1533
+ expect {@spy.send_post_to_community :to_community => @public_community_r, :post => @spy_post}.to raise_error
1534
+ expect {@spy.send_post_to_community :to_community => @private_community, :post => @spy_post}.to raise_error
1535
+
1536
+ @talisman_post = @talisman.posts.create :body => "morozovm_post_test_body"
1537
+ @morozovm.mute :user => @talisman, :in_community => @public_community_r
1538
+ @morozovm.mute :user => @talisman, :in_community => @private_community
1539
+ @public_community_r.reload
1540
+ @private_community.reload
1541
+ expect {@talisman.send_post_to_community :to_community => @public_community_r, :post => @talisman_post}.to raise_error
1542
+ expect {@talisman.send_post_to_community :to_community => @private_community, :post => @talisman_post}.to raise_error
1543
+ end
1544
+
1545
+ it "admin should be a writer" do
1546
+ @public_community = Community.create :name => "Community", :owner_id => @morozovm.id
1547
+ @public_community.default_user_access = 'r'
1548
+ @public_community.save
1549
+ @salkar.join @public_community
1550
+ @salkar.reload
1551
+ @public_community.reload
1552
+ @morozovm.reload
1553
+ @public_community.include_writer?(@salkar).should == false
1554
+
1555
+ @public_community.add_admin :admin => @morozovm, :user => @salkar
1556
+ @public_community.reload
1557
+ @salkar.reload
1558
+ @public_community.include_writer?(@salkar).should == true
687
1559
  end
688
1560
 
689
1561
  end