test/dummy/spec/functional/community_spec.rb in inkwell-1.2.0 vs test/dummy/spec/functional/community_spec.rb in inkwell-1.4.1

- old
+ new

@@ -9,26 +9,21 @@ @community_1 = Community.create :name => "Community_1", :owner_id => @talisman.id @salkar_post = @salkar.posts.create :body => "salkar_post_test_body" @salkar.reload @talisman.reload @morozovm.reload + @community_1.reload end it "user should been added to community" do - users_ids = ActiveSupport::JSON.decode @community_1.users_ids - users_ids.size.should == 1 - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 0 + ::Inkwell::CommunityUser.where(:user_id => @talisman.id, :community_id => @community_1.id).size.should == 1 + ::Inkwell::CommunityUser.where(:user_id => @salkar.id, :community_id => @community_1.id).empty?.should == true + @salkar.communities_row.size.should == 0 @community_1.add_user :user => @salkar @community_1.reload @salkar.reload - users_ids = ActiveSupport::JSON.decode @community_1.users_ids - users_ids.size.should == 2 - users_ids[1].should == @salkar.id - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id"=>@community_1.id, "a"=>"w"} + ::Inkwell::CommunityUser.where(:user_id => @salkar.id, :community_id => @community_1.id).should be end it "community's posts should been transferred to user timeline" do @salkar_post1 = @salkar.posts.create :body => "salkar_post_test_body1" @salkar_post2 = @salkar.posts.create :body => "salkar_post_test_body2" @@ -146,26 +141,20 @@ expect { @community_1.add_user @salkar }.to raise_error end it "user should be in community after added (include_user?)" do @community_1.include_user?(@salkar).should == false - @salkar.communities_info = ActiveSupport::JSON.encode [{"c_id"=>@community_1.id, "a"=>"w"}] - @community_1.users_ids = "[#{@salkar.id}]" - @community_1.save - @salkar.save + ::Inkwell::CommunityUser.create :user_id => @salkar.id, :community_id => @community_1.id, :active => true @community_1.include_user?(@salkar).should == true end it "user should not be admin" do @community_1.include_admin?(@salkar).should == false end it "user should be admin" do - @community_1.admins_info = ActiveSupport::JSON.encode [{'admin_id' => @salkar.id}] - @community_1.save - @community_1.reload - @community_1.include_admin?(@salkar).should == true + @community_1.include_admin?(@talisman).should == true end it "user should remove himself from community" do @community_1.add_user :user => @salkar @community_1.reload @@ -173,11 +162,11 @@ @community_1.include_user?(@salkar).should be @community_1.remove_user :user => @salkar @community_1.reload @salkar.reload @community_1.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1 + @community_1.admins_row.size.should == 1 end it "community owner should not remove himself from community" do @community_1.reload @talisman.reload @@ -245,57 +234,41 @@ tline.where(:item_id => @morozovm_post2.id, :item_type => ::Inkwell::Constants::ItemTypes::POST).first.should == nil ActiveSupport::JSON.decode(tline.where(:item_id => @salkar_post8.id, :item_type => ::Inkwell::Constants::ItemTypes::POST).first.from_source).should == [Hash['user_id' => @salkar.id, 'type' => 'following']] end it "admin level of user should be returned" do - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 3}] - @community_1.save - @community_1.admin_level_of(@salkar).should == 3 + @community_1.admin_level_of(@talisman).should == 0 end it "admin level of user should not be returned" do expect { @community_1.admin_level_of(@salkar) }.to raise_error end it "admin should be added" do - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}] - @community_1.save - @community_1.add_user :user => @salkar @community_1.add_user :user => @morozovm + @community_1.add_admin :admin => @talisman, :user => @morozovm @community_1.reload @salkar.reload - @morozovm.reload - @community_1.add_admin :admin => @salkar, :user => @morozovm - @community_1.reload - @salkar.reload @community_1.include_admin?(@morozovm).should == true @community_1.admin_level_of(@morozovm).should == 1 end it "admin should not be added" do expect { @community_1.add_admin(:user => @salkar) }.to raise_error expect { @community_1.add_admin(:user => @salkar, :admin => @talisman) }.to raise_error expect { @community_1.add_admin(:user => "@salkar", :admin => "@talisman") }.to raise_error - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}] - @community_1.save @community_1.add_user :user => @salkar - @community_1.add_user :user => @morozovm - @community_1.reload - @salkar.reload - @morozovm.reload expect { @community_1.add_admin :admin => @salkar, :user => @salkar }.to raise_error - @community_1.reload - @salkar.reload - ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1 + + @community_1.admins_row.size.should == 1 end it "admin should be removed" do - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}] - @community_1.save @community_1.add_user :user => @salkar @community_1.add_user :user => @morozovm + @community_1.add_admin :user => @salkar, :admin => @talisman @community_1.reload @salkar.reload @morozovm.reload @community_1.add_admin :admin => @salkar, :user => @morozovm @community_1.reload @@ -304,11 +277,11 @@ @community_1.remove_admin :admin => @salkar, :user => @morozovm @community_1.reload @morozovm.reload @community_1.include_admin?(@salkar).should == true @community_1.include_admin?(@morozovm).should == false - ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1 + @community_1.admins_row.size.should == 2 @community_1.add_admin :admin => @salkar, :user => @morozovm @community_1.reload @morozovm.reload @community_1.include_admin?(@morozovm).should == true @@ -321,18 +294,13 @@ it "admin should not be removed" do expect { @community_1.remove_admin :admin => @salkar, :user => @morozovm }.to raise_error expect { @community_1.remove_admin :admin => "@salkar", :user => "@morozovm" }.to raise_error expect { @community_1.remove_admin :user => @morozovm }.to raise_error - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}] - @community_1.save @community_1.add_user :user => @salkar @community_1.add_user :user => @morozovm - @community_1.reload - @salkar.reload - @morozovm.reload - expect { @community_1.remove_admin :user => @salkar, :admin => @salkar }.to raise_error + @community_1.add_admin :user => @salkar, :admin => @talisman @community_1.add_admin :admin => @salkar, :user => @morozovm @community_1.reload @morozovm.reload expect { @community_1.remove_admin :user => @salkar, :admin => @morozovm }.to raise_error @@ -545,23 +513,18 @@ @morozovm.reload expect { @community_1.remove_post :post => @salkar_post, :user => @morozovm }.to raise_error end it "user should join community" do - users_ids = ActiveSupport::JSON.decode @community_1.users_ids - users_ids.size.should == 1 - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 0 + @community_1.users_row.size.should == 1 + @salkar.communities_row.size.should == 0 @salkar.join @community_1 @community_1.reload @salkar.reload - users_ids = ActiveSupport::JSON.decode @community_1.users_ids - users_ids.size.should == 2 - users_ids[1].should == @salkar.id - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id"=>@community_1.id, "a"=>"w"} + @community_1.users_row.size.should == 2 + @community_1.include_user?(@salkar).should == true + @salkar.communities_row.should == [@community_1.id] end it "user should leave community" do @community_1.add_user :user => @salkar @community_1.reload @@ -569,11 +532,11 @@ @community_1.include_user?(@salkar).should be @salkar.leave @community_1 @community_1.reload @salkar.reload @community_1.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1 + @community_1.include_admin?(@salkar).should == false end it "user should be kicked from community" do @community_1.add_user :user => @salkar @community_1.reload @@ -582,11 +545,10 @@ @talisman.reload @talisman.kick :user => @salkar, :from_community => @community_1 @community_1.reload @salkar.reload @community_1.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1 end it "post should be sended to community" do @community_1.add_user :user => @salkar ::Inkwell::BlogItem.where(:owner_id => @community_1.id, :owner_type => ::Inkwell::Constants::OwnerTypes::COMMUNITY, :item_id => @salkar_post.id, :item_type => ::Inkwell::Constants::ItemTypes::POST).size.should == 0 @@ -632,42 +594,35 @@ @salkar_post.reload ActiveSupport::JSON.decode(@salkar_post.communities_ids).size.should == 0 end it "admin permissions should be granted" do - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}] - @community_1.save @community_1.add_user :user => @salkar @community_1.add_user :user => @morozovm + @community_1.add_admin :user => @salkar, :admin => @talisman @community_1.reload @salkar.reload @morozovm.reload @salkar.grant_admin_permissions :to_user => @morozovm, :in_community => @community_1 @community_1.reload @salkar.reload @community_1.include_admin?(@morozovm).should == true - @community_1.admin_level_of(@morozovm).should == 1 + @community_1.admin_level_of(@morozovm).should == 2 end it "admin permissions should be revoked" do - @community_1.admins_info = ActiveSupport::JSON.encode [{:admin_id => @salkar.id, :admin_level => 0}] - @community_1.save @community_1.add_user :user => @salkar @community_1.add_user :user => @morozovm - @community_1.reload - @salkar.reload - @morozovm.reload + @community_1.add_admin :user => @salkar, :admin => @talisman @community_1.add_admin :admin => @salkar, :user => @morozovm - @community_1.reload - @morozovm.reload @community_1.include_admin?(@morozovm).should == true @salkar.revoke_admin_permissions :user => @morozovm, :in_community => @community_1 @community_1.reload @morozovm.reload @community_1.include_admin?(@salkar).should == true @community_1.include_admin?(@morozovm).should == false - ActiveSupport::JSON.decode(@community_1.admins_info).size.should == 1 + @community_1.admins_row.size.should == 2 end it "community row should be returned for user" do @community_2 = Community.create :name => "Community_1", :owner_id => @talisman.id @community_3 = Community.create :name => "Community_1", :owner_id => @talisman.id @@ -685,64 +640,63 @@ it "private community with default W access should be created" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.reload @morozovm.reload @private_community.public.should == false - @private_community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" - @private_community.users_ids.should == "[#{@morozovm.id}]" - ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id"=>@private_community.id, "a"=>"w"}] + @private_community.writers_row.should == [@morozovm.id] + @private_community.users_row.should == [@morozovm.id] + @private_community.admins_row.should == [@morozovm.id] + @private_community.admin_level_of(@morozovm).should == 0 end it "private community with default R access should be created" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.default_user_access = 'r' @private_community.save @private_community.reload @morozovm.reload @private_community.public.should == false - @private_community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" - @private_community.users_ids.should == "[#{@morozovm.id}]" - ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id"=>@private_community.id, "a"=>"w"}] + @private_community.include_user?(@morozovm).should == true + @private_community.include_writer?(@morozovm).should == true + @private_community.include_admin?(@morozovm).should == true + @private_community.admin_level_of(@morozovm).should == 0 end it "public community with default W access should be created" do @w_community = Community.create :name => "Community", :owner_id => @morozovm.id @w_community.reload @morozovm.reload @w_community.public.should == true - @w_community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]" - @w_community.writers_ids.should == "[#{@morozovm.id}]" - @w_community.users_ids.should == "[#{@morozovm.id}]" - ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id"=>@w_community.id, "a"=>"w"}] + @w_community.admins_row.should == [@morozovm.id] + @w_community.admin_level_of(@morozovm).should == 0 + @w_community.writers_row.should == [@morozovm.id] + @w_community.users_row.should == [@morozovm.id] end it "public community with default R access should be created" do @community = Community.create :name => "Community", :owner_id => @morozovm.id @community.default_user_access = 'r' @community.save @community.reload @morozovm.reload @community.public.should == true - @community.admins_info.should == "[{\"admin_id\":#{@morozovm.id},\"admin_level\":0}]" - @community.writers_ids.should == "[#{@morozovm.id}]" - @community.users_ids.should == "[#{@morozovm.id}]" - ActiveSupport::JSON.decode(@morozovm.communities_info).should == [{"c_id" => @community.id, "a" => "w"}] + + relation = ::Inkwell::CommunityUser.where(:user_id => @morozovm.id, :community_id => @community.id).first + relation.should be + relation.is_admin.should == true + relation.user_access.should == "w" end it "added to public community with default W access user should have W access" do @w_community = Community.create :name => "Community", :owner_id => @morozovm.id @w_community.reload @morozovm.reload @w_community.add_user :user => @salkar @w_community.reload @salkar.reload @w_community.include_user?(@salkar).should == true - ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @w_community.id, "a" => "w"}] - ActiveSupport::JSON.decode(@w_community.users_ids).should == [@morozovm.id, @salkar.id] - ActiveSupport::JSON.decode(@w_community.writers_ids).should == [@morozovm.id, @salkar.id] + ::Inkwell::CommunityUser.exists?(:community_id => @w_community.id, :user_id => @salkar.id, :user_access => "w").should == true end it "added to public community with default R access user should have R access" do @community = Community.create :name => "Community", :owner_id => @morozovm.id @community.default_user_access = 'r' @@ -751,27 +705,24 @@ @morozovm.reload @community.add_user :user => @salkar @community.reload @salkar.reload @community.include_user?(@salkar).should == true - ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @community.id, "a" => "r"}] - ActiveSupport::JSON.decode(@community.users_ids).should == [@morozovm.id, @salkar.id] - ActiveSupport::JSON.decode(@community.writers_ids).should == [@morozovm.id] + ::Inkwell::CommunityUser.exists?(:community_id => @community.id, :user_id => @salkar.id, :user_access => "r").should == true end it "added to private community with default W access user should have W access" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar @private_community.reload @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm @salkar.reload @private_community.reload @private_community.include_user?(@salkar).should == true - @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]" + @private_community.users_row.should == [@morozovm.id, @salkar.id] + @private_community.writers_row.should == [@morozovm.id, @salkar.id] @salkar.communities_row.should == [@private_community.id] - ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @private_community.id, "a" => "w"}] end it "added to private community with default R access user should have R access" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.default_user_access = 'r' @@ -780,21 +731,19 @@ @private_community.reload @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm @salkar.reload @private_community.reload @private_community.include_user?(@salkar).should == true - @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" + @private_community.users_row.should == [@morozovm.id, @salkar.id] + @private_community.writers_row.should == [@morozovm.id] @salkar.communities_row.should == [@private_community.id] - ActiveSupport::JSON.decode(@salkar.communities_info).should == [{"c_id" => @private_community.id, "a" => "r"}] end it "request invitation should be created (include_invitation_request?)" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar - @private_community.reload - @private_community.invitations_uids.should == "[#{@salkar.id}]" + ::Inkwell::CommunityUser.exists?(:user_id => @salkar.id, :community_id => @private_community.id, :active => false, :asked_invitation => true).should == true @private_community.include_invitation_request?(@salkar).should == true end it "request invitation should be created (include_invitation_request?)" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -812,27 +761,24 @@ end it "invitation request should be created" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar - @private_community.reload - @private_community.invitations_uids.should == "[#{@salkar.id}]" + ::Inkwell::CommunityUser.exists?(:user_id => @salkar.id, :community_id => @private_community.id, :active => false, :asked_invitation => true).should == true end it "invitation request should not be created" do expect { @community_1.create_invitation_request(@salkar) }.to raise_error @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false - @private_community.banned_ids = "[#{@talisman.id}]" - @private_community.save + ::Inkwell::CommunityUser.create :user_id => @talisman.id, :community_id => @private_community.id, :active => false, :banned => true expect { @private_community.create_invitation_request(@talisman) }.to raise_error @private_community.create_invitation_request(@salkar) expect { @private_community.create_invitation_request(@salkar) }.to raise_error end it "user should not be added to public community cause he is banned" do - @community_1.banned_ids = "[#{@morozovm.id}]" - @community_1.save + ::Inkwell::CommunityUser.create :user_id => @morozovm.id, :community_id => @community_1.id, :active => false, :banned => true expect { @morozovm.join @community_1 }.to raise_error end it "error should be raised on trying to add to community user who already added to it" do @salkar.join @community_1 @@ -866,12 +812,12 @@ @private_community.reload @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm @salkar.reload @private_community.reload @private_community.include_user?(@salkar).should == true - @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]" + @private_community.users_row.should == [@morozovm.id, @salkar.id] + @private_community.writers_row.should == [@morozovm.id, @salkar.id] @salkar.communities_row.should == [@private_community.id] end it "invitation request should not be accepted" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -892,21 +838,21 @@ @private_community.add_user :user => @salkar #only for test @private_community.reload @salkar.reload @private_community.include_user?(@salkar).should == true - @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]" + @private_community.users_row.should == [@morozovm.id, @salkar.id] + @private_community.writers_row.should == [@morozovm.id, @salkar.id] @salkar.communities_row.should == [@private_community.id] @private_community.remove_user :admin => @morozovm, :user => @salkar @private_community.reload @salkar.reload @private_community.include_user?(@salkar).should == false - @private_community.users_ids.should == "[#{@morozovm.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" + @private_community.users_row.should == [@morozovm.id] + @private_community.writers_row.should == [@morozovm.id] @salkar.communities_row.should == [] end it "admin should be removed from private community" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -915,23 +861,23 @@ @private_community.reload @salkar.reload @private_community.include_user?(@salkar).should == true @private_community.include_admin?(@salkar).should == true - @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should_not == nil + @private_community.users_row.should == [@morozovm.id, @salkar.id] + @private_community.writers_row.should == [@morozovm.id, @salkar.id] + @private_community.admins_row.should == [@morozovm.id, @salkar.id] @salkar.communities_row.should == [@private_community.id] @private_community.remove_user :admin => @morozovm, :user => @salkar @private_community.reload @salkar.reload @private_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil - @private_community.users_ids.should == "[#{@morozovm.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" + @private_community.users_row.should == [@morozovm.id] + @private_community.writers_row.should == [@morozovm.id] + @private_community.admins_row.should == [@morozovm.id] @salkar.communities_row.should == [] end it "user should leave private community" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -944,13 +890,10 @@ @salkar.leave @private_community @salkar.reload @private_community.reload @private_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil - @private_community.users_ids.should == "[#{@morozovm.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" @salkar.communities_row.should == [] end it "user should be kicked from private community" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -963,13 +906,11 @@ @morozovm.kick :user => @salkar, :from_community => @private_community @salkar.reload @private_community.reload @private_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@private_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should == nil - @private_community.users_ids.should == "[#{@morozovm.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id}]" + ::Inkwell::CommunityUser.where(:community_id => @private_community.id).size.should == 1 @salkar.communities_row.should == [] end it "user should not join private community" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -985,23 +926,21 @@ @salkar.reload @public_community.reload @public_community.include_user?(@salkar).should == true @public_community.include_admin?(@salkar).should == true - @public_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @public_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should_not == nil + @public_community.users_row.should == [@morozovm.id, @salkar.id] + @public_community.writers_row.should == [@morozovm.id, @salkar.id] @salkar.communities_row.should == [@public_community.id] @morozovm.kick :user => @salkar, :from_community => @public_community @salkar.reload @public_community.reload @public_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should == nil - @public_community.users_ids.should == "[#{@morozovm.id}]" - @public_community.writers_ids.should == "[#{@morozovm.id}]" + @public_community.users_row.should == [@morozovm.id] + @public_community.writers_row.should == [@morozovm.id] @salkar.communities_row.should == [] end it "user should be muted" do @public_community = Community.create :name => "Community", :owner_id => @morozovm.id @@ -1167,33 +1106,31 @@ @public_community.add_admin :user => @salkar, :admin => @morozovm @salkar.reload @public_community.reload @morozovm.reload - ActiveSupport::JSON.decode(@public_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should_not == nil + @public_community.include_user?(@salkar).should == true @public_community.include_banned_user?(@salkar).should == false @public_community.ban_user :user => @salkar, :admin => @morozovm @public_community.reload @public_community.include_banned_user?(@salkar).should == true @public_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@public_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar @private_community.reload @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm @private_community.add_admin :user => @salkar, :admin => @morozovm @salkar.reload @private_community.reload - ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should_not == nil + @private_community.include_user?(@salkar).should == true @private_community.include_banned_user?(@salkar).should == false @private_community.ban_user :user => @salkar, :admin => @morozovm @private_community.reload @private_community.include_banned_user?(@salkar).should == true @private_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@private_community.admins_info).index{|item| item['admin_id'] == @salkar.id}.should == nil end it "user with request invitation should be banned" do @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar @@ -1286,17 +1223,17 @@ @public_community.add_admin :user => @salkar, :admin => @morozovm @salkar.reload @public_community.reload @morozovm.reload - ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should_not == nil + @public_community.include_admin?(@salkar).should == true @public_community.include_banned_user?(@salkar).should == false @morozovm.ban :user => @salkar, :in_community => @public_community @public_community.reload @public_community.include_banned_user?(@salkar).should == true @public_community.include_user?(@salkar).should == false - ActiveSupport::JSON.decode(@public_community.admins_info).index { |item| item['admin_id'] == @salkar.id }.should == nil + @public_community.include_admin?(@salkar).should == false end it "user should unban another user" do @private_community = Community.create :name => "Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar @@ -1559,24 +1496,23 @@ end it "user should be able to request invitation to private community" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @salkar.request_invitation @private_community - @private_community.reload - @private_community.invitations_uids.should == "[#{@salkar.id}]" + ::Inkwell::CommunityUser.exists?(:user_id => @salkar.id, :community_id => @private_community.id, :active => false, :asked_invitation => true).should == true end it "admin should be able to accept invitation request" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @private_community.create_invitation_request @salkar @private_community.reload @morozovm.approve_invitation_request :user => @salkar, :community => @private_community @salkar.reload @private_community.reload @private_community.include_user?(@salkar).should == true - @private_community.users_ids.should == "[#{@morozovm.id},#{@salkar.id}]" - @private_community.writers_ids.should == "[#{@morozovm.id},#{@salkar.id}]" + @private_community.users_row.should == [@morozovm.id,@salkar.id] + @private_community.writers_row.should == [@morozovm.id,@salkar.id] @salkar.communities_row.should == [@private_community.id] end it "admin should be able to reject invitation request" do @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false @@ -1626,26 +1562,17 @@ @public_community.reload @salkar.reload @talisman.reload @spy.reload - writers_ids = ActiveSupport::JSON.decode(@public_community.writers_ids) + writers_ids = @public_community.writers_row writers_ids.include?(@salkar.id).should == true writers_ids.include?(@talisman.id).should == true writers_ids.include?(@spy.id).should == false @public_community.include_writer?(@salkar).should == true @public_community.include_writer?(@talisman).should == true @public_community.include_writer?(@spy).should == false - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id"=>@public_community.id, "a"=>"w"} - communities_info = ActiveSupport::JSON.decode @talisman.communities_info - communities_info.size.should == 2 - communities_info[1].should == {"c_id" => @public_community.id, "a" => "w"} - communities_info = ActiveSupport::JSON.decode @spy.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @public_community.id, "a" => "r"} end it "write access should be granted in the private community" do @private_community = Community.create :name => "community", :owner_id => @morozovm.id, :public => false @private_community.default_user_access = 'r' @@ -1665,42 +1592,32 @@ @private_community.reload @salkar.reload @talisman.reload @spy.reload - writers_ids = ActiveSupport::JSON.decode(@private_community.writers_ids) + writers_ids = @private_community.writers_row writers_ids.include?(@salkar.id).should == true writers_ids.include?(@talisman.id).should == true writers_ids.include?(@spy.id).should == false @private_community.include_writer?(@salkar).should == true @private_community.include_writer?(@talisman).should == true @private_community.include_writer?(@spy).should == false - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @private_community.id, "a" => "w"} - communities_info = ActiveSupport::JSON.decode @talisman.communities_info - communities_info.size.should == 2 - communities_info[1].should == {"c_id" => @private_community.id, "a" => "w"} - communities_info = ActiveSupport::JSON.decode @spy.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @private_community.id, "a" => "r"} end - it "error should not raised when W access granted to user with W access" do + it "error should raised when W access granted to user with W access" do @public_community = Community.create :name => "community", :owner_id => @morozovm.id @salkar.join @public_community @talisman.join @public_community @spy.join @public_community @public_community.reload @salkar.reload @talisman.reload @spy.reload - @public_community.set_write_access @public_community.users_row - writers_ids = ActiveSupport::JSON.decode(@public_community.writers_ids) - writers_ids.should == [@morozovm.id, @salkar.id, @talisman.id, @spy.id] + expect {@public_community.set_write_access @public_community.users_row}.to raise_error + (@public_community.writers_row & [@morozovm.id, @salkar.id, @talisman.id, @spy.id]).size.should == 4 end it "passed empty array should not lead to error" do @public_community = Community.create :name => "community", :owner_id => @morozovm.id @public_community.set_write_access [] @@ -1708,11 +1625,10 @@ @private_community.set_write_access [] end it "write access should not be granted" do @public_community = Community.create :name => "community", :owner_id => @morozovm.id - expect {@public_community.set_write_access [@salkar.id, @talisman.id]}.to raise_error expect {@public_community.set_write_access [@talisman.id]}.to raise_error expect {@public_community.set_write_access @talisman}.to raise_error expect {@public_community.set_write_access [-1]}.to raise_error end @@ -1732,26 +1648,17 @@ @public_community.reload @salkar.reload @talisman.reload @spy.reload - writers_ids = ActiveSupport::JSON.decode(@public_community.writers_ids) + writers_ids = @public_community.writers_row writers_ids.include?(@salkar.id).should == false writers_ids.include?(@talisman.id).should == false writers_ids.include?(@spy.id).should == true @public_community.include_writer?(@salkar).should == false @public_community.include_writer?(@talisman).should == false @public_community.include_writer?(@spy).should == true - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @public_community.id, "a" => "r"} - communities_info = ActiveSupport::JSON.decode @talisman.communities_info - communities_info.size.should == 2 - communities_info[1].should == {"c_id" => @public_community.id, "a" => "r"} - communities_info = ActiveSupport::JSON.decode @spy.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @public_community.id, "a" => "w"} end it "read access should be set in the private community" do @private_community = Community.create :name => "community", :owner_id => @morozovm.id, :public => false @@ -1769,29 +1676,23 @@ @private_community.reload @salkar.reload @talisman.reload @spy.reload - writers_ids = ActiveSupport::JSON.decode(@private_community.writers_ids) - writers_ids.include?(@salkar.id).should == false - writers_ids.include?(@talisman.id).should == false - writers_ids.include?(@spy.id).should == true + salkar_relation = ::Inkwell::CommunityUser.where(:user_id => @salkar.id, :community_id => @private_community.id).first + spy_relation = ::Inkwell::CommunityUser.where(:user_id => @spy.id, :community_id => @private_community.id).first + talisman_relation = ::Inkwell::CommunityUser.where(:user_id => @talisman.id, :community_id => @private_community.id).first + salkar_relation.user_access.should == "r" + spy_relation.user_access.should == "w" + talisman_relation.user_access.should == "r" + @private_community.include_writer?(@salkar).should == false @private_community.include_writer?(@talisman).should == false @private_community.include_writer?(@spy).should == true - communities_info = ActiveSupport::JSON.decode @salkar.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @private_community.id, "a" => "r"} - communities_info = ActiveSupport::JSON.decode @talisman.communities_info - communities_info.size.should == 2 - communities_info[1].should == {"c_id" => @private_community.id, "a" => "r"} - communities_info = ActiveSupport::JSON.decode @spy.communities_info - communities_info.size.should == 1 - communities_info[0].should == {"c_id" => @private_community.id, "a" => "w"} end - it "error should not raised when R access set to user with R access" do + it "error shouldraised when R access set to user with R access" do @public_community = Community.create :name => "community", :owner_id => @morozovm.id @public_community.default_user_access = 'r' @public_community.save @salkar.join @public_community @talisman.join @public_community @@ -1800,13 +1701,12 @@ @public_community.reload @salkar.reload @talisman.reload @spy.reload - @public_community.set_read_access (@public_community.users_row - [@morozovm.id]) - writers_ids = ActiveSupport::JSON.decode(@public_community.writers_ids) - writers_ids.should == [@morozovm.id] + expect { @public_community.set_read_access (@public_community.users_row - [@morozovm.id]) }.to raise_error + @public_community.writers_row.should == [@morozovm.id] end it "passed empty array should not lead to error" do @public_community = Community.create :name => "community", :owner_id => @morozovm.id @public_community.set_read_access [] @@ -1849,8 +1749,425 @@ @salkar.reload @public_community.reload @morozovm.reload @talisman.reload @public_community.writers_row.should == [@morozovm.id, @talisman.id, @salkar.id, @spy.id] + end + + it "counters should be incremented when user enters into the community" do + @community_1.reload + @community_1.add_user :admin => @talisman, :user => @salkar + @community_1.reload + @community_1.user_count.should == 2 + @salkar.reload + @salkar.community_count.should == 1 + @talisman.reload + @talisman.community_count.should == 1 + end + + it "counters should be incremented for community owner when he creates community" do + @community_1.reload + @community_1.user_count.should == 1 + @talisman.community_count.should == 1 + end + + it "counters should be decremented when user leaves community" do + @community_1.reload + @community_1.add_user :admin => @talisman, :user => @salkar + @community_1.reload + @salkar.reload + @community_1.user_count.should == 2 + @community_1.remove_user :admin => @talisman, :user => @salkar + @community_1.reload + @community_1.user_count.should == 1 + @salkar.reload + @salkar.community_count.should == 0 + @talisman.reload + @talisman.community_count.should == 1 + end + + it "counters should be decremented when community has been destroyed" do + @community_1.add_user :admin => @talisman, :user => @salkar + @community_1.destroy + @salkar.reload + @salkar.community_count.should == 0 + @talisman.reload + @talisman.community_count.should == 0 + end + + it "writer counter should be incremented when user enters to community" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.writer_count.should == 2 + end + + it "writer counter should not be incremented when user enters to community" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.default_user_access = 'r' + @public_community.save + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.writer_count.should == 1 + end + + it "writer counter should be incremented for community owner" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.reload + @public_community.writer_count.should == 1 + end + + it "writer counter should be decremented when user is removed" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.remove_user :user => @salkar + @public_community.reload + @public_community.writer_count.should == 1 + end + + it "writer counter should be decremented when user is removed" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.default_user_access = 'r' + @public_community.save + @public_community.add_user :user => @salkar + @public_community.remove_user :user => @salkar + @public_community.reload + @public_community.writer_count.should == 1 + end + + it "writer count should be incremented when admin gives W access to user" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.default_user_access = 'r' + @public_community.save + @public_community.reload + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.set_write_access [@salkar.id] + @public_community.reload + @public_community.writer_count.should == 2 + end + + it "writer and user counters should be decremeted when user destroy his accaunt" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.reload + @public_community.add_user :user => @salkar + @public_community.reload + @salkar.reload + @salkar.destroy + @public_community.reload + @public_community.user_count.should == 1 + @public_community.writer_count.should == 1 + end + + it "writer count should be decremented when admin set R access for user" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.reload + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.set_read_access [@salkar.id] + @public_community.reload + @public_community.writer_count.should == 1 + end + + it "reader count should be returned for community" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.reload + @public_community.reader_count.should == 0 + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.reader_count.should == 0 + @public_community.set_read_access [@salkar.id] + @public_community.reload + @public_community.reader_count.should == 1 + @public_community.default_user_access = 'r' + @public_community.save + @public_community.add_user :user => @talisman + @public_community.reload + @public_community.reader_count.should == 2 + end + + it "community should not be created if owner id is nonexistent" do + c_size = Community.all.size + expect {@public_community = Community.create :name => "community", :owner_id => -1}.to raise_error + Community.all.size.should == c_size + end + + it "admin counter should be incremented when admin is added" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.reload + @public_community.add_user :user => @salkar + @public_community.reload + @public_community.admin_count.should == 1 + @public_community.add_admin :user => @salkar, :admin => @morozovm + @public_community.reload + @public_community.admin_count.should == 2 + end + + it "admin counter should be 1 after community is created" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.reload + @public_community.admin_count.should == 1 + end + + it "admin counter should be decremented after admin is removed" do + @community_1.add_user :user => @salkar + @community_1.add_admin :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.admin_count.should == 2 + @community_1.remove_admin :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.admin_count.should == 1 + end + + it "admin counter should be decremeted when admin is removed from community" do + @community_1.add_user :user => @salkar + @community_1.add_admin :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.admin_count.should == 2 + @community_1.remove_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.admin_count.should == 1 + end + + it "admin counter should be decremented when admin destroy his account" do + @community_1.add_user :user => @salkar + @community_1.add_admin :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.admin_count.should == 2 + @salkar.destroy + @community_1.reload + @community_1.admin_count.should == 1 + end + + it "muted counter should be incremented when admin mutes user" do + @community_1.add_user :user => @salkar + @community_1.muted_count.should == 0 + @community_1.mute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 1 + end + + it "muted counter should be decreaded when admin status is getting by muted user" do + @community_1.add_user :user => @salkar + @community_1.mute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 1 + @community_1.add_admin :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 0 + end + + it "muted counter should be decreased when admin unmutes user" do + @community_1.add_user :user => @salkar + @community_1.mute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 1 + @community_1.unmute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 0 + end + + it "muted counter should be decreased when muted user is removed from community" do + @community_1.add_user :user => @salkar + @community_1.mute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 1 + @community_1.remove_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 0 + end + + it "muted counter should be decreased when muted user destroys his accaunt" do + @community_1.add_user :user => @salkar + @community_1.mute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_count.should == 1 + @salkar.destroy + @community_1.reload + @community_1.muted_count.should == 0 + end + + it "banned counter should be increased when admin bans user" do + @community_1.add_user :user => @salkar + @community_1.ban_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.banned_count.should == 1 + @community_1.include_banned_user?(@salkar).should == true + end + + it "banned counter should be decreased when admin unbans user" do + @community_1.add_user :user => @salkar + @community_1.ban_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.banned_count.should == 1 + @community_1.include_banned_user?(@salkar).should == true + @community_1.unban_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.banned_count.should == 0 + @community_1.include_banned_user?(@salkar).should == false + end + + it "banned counter should be decremeted when user destroys his accaunt" do + @community_1.add_user :user => @salkar + @community_1.ban_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.banned_count.should == 1 + @salkar.destroy + @community_1.reload + @community_1.banned_count.should == 0 + end + + it "user counter should be decremented when admin ban user" do + @community_1.add_user :user => @salkar + @community_1.reload + @community_1.user_count.should == 2 + @community_1.ban_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.user_count.should == 1 + end + + it "invitation counter should be incremented when user asks invitation" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.reload + @private_community.invitation_count.should == 0 + @private_community.create_invitation_request @salkar + @private_community.reload + @private_community.invitation_count.should == 1 + end + + it "invitation counter should be decremented when admin accept invitation" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.reload + @private_community.invitation_count.should == 0 + @private_community.create_invitation_request @salkar + @private_community.reload + @private_community.invitation_count.should == 1 + @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm + @private_community.reload + @private_community.invitation_count.should == 0 + end + + it "invitation counter should be decremented when admin reject invitation" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.reload + @private_community.invitation_count.should == 0 + @private_community.create_invitation_request @salkar + @private_community.reload + @private_community.invitation_count.should == 1 + @private_community.reject_invitation_request :user => @salkar, :admin => @morozovm + @private_community.reload + @private_community.invitation_count.should == 0 + end + + it "invitation counter should be decremented when admin ban asked user" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.reload + @private_community.invitation_count.should == 0 + @private_community.create_invitation_request @salkar + @private_community.reload + @private_community.invitation_count.should == 1 + @private_community.ban_user :user => @salkar, :admin => @morozovm + @private_community.reload + @private_community.invitation_count.should == 0 + end + + it "invitation counter should be decremented when user destroys his accaunt" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.reload + @private_community.invitation_count.should == 0 + @private_community.create_invitation_request @salkar + @private_community.reload + @private_community.invitation_count.should == 1 + @salkar.destroy + @private_community.reload + @private_community.invitation_count.should == 0 + end + + it "communities should be returned for their member" do + @public_community = Community.create :name => "Community", :owner_id => @morozovm.id + @talisman.join @public_community + communities = @talisman.communities + communities.include?(@community_1).should == true + communities.include?(@public_community).should == true + communities.size.should == 2 + end + + it "communities should be returned for their member" do + @public_community = Community.create :name => "Community", :owner_id => @morozovm.id + @talisman.join @public_community + @salkar.join @public_community + @spy.join @public_community + users = @public_community.users + users.include?(@morozovm).should == true + users.include?(@talisman).should == true + users.include?(@salkar).should == true + users.include?(@spy).should == true + users.size.should == 4 + end + + it "admins should be returned for community" do + @community_1.admins.should == [@talisman] + @community_1.add_user :user => @salkar, :admin => @talisman + @community_1.admins.should == [@talisman] + @community_1.add_admin :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.admins.should == [@talisman, @salkar] + end + + it "writers should be returned for community" do + @public_community = Community.create :name => "community", :owner_id => @morozovm.id + @public_community.default_user_access = 'r' + @public_community.save + @public_community.reload + @public_community.writers.should == [@morozovm] + @salkar.join @public_community + @public_community.reload + @public_community.writers.should == [@morozovm] + @public_community.set_write_access [@salkar.id] + @public_community.reload + @public_community.writers.should == [@morozovm, @salkar] + end + + it "muted users should be returned for community" do + @community_1.muted_users.should == [] + @community_1.add_user :user => @salkar + @community_1.mute_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.muted_users.should == [@salkar] + end + + it "banned users should be returned for community" do + @community_1.banned_users.should == [] + @community_1.add_user :user => @salkar + @community_1.ban_user :user => @salkar, :admin => @talisman + @community_1.reload + @community_1.banned_users.should == [@salkar] + end + + it "asked invitation users should be returned for community" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.asked_invitation_users.should == [] + @private_community.create_invitation_request @salkar + @private_community.reload + @private_community.asked_invitation_users.should == [@salkar] + @private_community.accept_invitation_request :user => @salkar, :admin => @morozovm + @private_community.reload + @private_community.asked_invitation_users.should == [] + end + + it "invitation_uids should be returned for community" do + @private_community = Community.create :name => "Private Community", :owner_id => @morozovm.id, :public => false + @private_community.invitations_row.should == [] + @private_community.create_invitation_request @salkar + @private_community.create_invitation_request @talisman + @private_community.reload + @private_community.invitations_row.should == [@salkar.id, @talisman.id] + end + + it "user should not be destroyed if he is owner of some communities" do + expect {@talisman.destroy}.to raise_error + @talisman.reload + @talisman.should be end end \ No newline at end of file