<commit_before>require "spec_helper"

describe MembershipsController, type: :controller do
  disconnect_sunspot
  let(:user){FactoryGirl.create :user}
  let(:other){FactoryGirl.create :user}

  describe "GET index" do
    before do
      sign_in user
      group = Group.create name: "foo"
      get :index, user_id: user.id
    end
    subject{response}
    it{should render_template :index}
  end

  describe "POST create" do
    before do
      sign_in user
      group = Group.create name: "foo"
      xhr :post, :create, user_id: user.id,
        membership: {group_id: group.id.to_s}, format: :json
    end
    context "with valid params" do
      it_behaves_like "success"
      it_behaves_like "render template", "create"
    end
  end

  describe "PATCH update" do
    let(:membership_params){{role: "editor"}}
    before do
      sign_in user
      group = Group.create name: "foo"
      membership = user.memberships.create group_id: group.id
      patch :update, user_id: user.id, id: membership.id,
        membership: membership_params, format: :json
    end
    it{should render_template :update}
  end

  describe "DELETE destroy" do
    context "when a user destroyed own membership" do
      before do
        sign_in user
        group = Group.create name: "foo"
        membership = user.memberships.create group_id: group.id
        delete :destroy, user_id: user.id,
          id: membership.id, format: :json
      end
      it{should render_template :destroy}<commit_msg>close #1273 revise memberships_controller spec<commit_after>require "spec_helper"

describe MembershipsController, type: :controller do
  disconnect_sunspot
  let(:user){FactoryGirl.create :user}
  let(:other){FactoryGirl.create :user}

  describe "GET index" do
    before do
      sign_in user
      group = Group.create name: "foo"
      get :index, user_id: user.id
    end
    subject{response}
    it{should render_template :index}
  end

  describe "POST create" do
    context "with valid params" do
      before do
        sign_in user
        group = Group.create name: "foo"
        xhr :post, :create, user_id: user.id,
          membership: {group_id: group.id.to_s}, format: :json
      end
      it_behaves_like "success"
      it_behaves_like "render template", "create"
    end
    context "with invalid params" do
      before do
        sign_in user
        xhr :post, :create, user_id: user.id,
          membership: {group_id: "unexisted_group"}, format: :json
      end
      it{expect render_template 'error/failed', status: 400}
    end
  end

  describe "PATCH update" do
    context "with invalid params" do
      let(:membership_params){{role: "editor"}}
      before do
        sign_in user
        group = Group.create name: "foo"
        membership = user.memberships.create group_id: group.id
        patch :update, user_id: user.id, id: membership.id,
          membership: membership_params, format: :json
      end
      it{should render_template :update}
    end
    context "with invalid params" do
      let(:membership_params){{role: "unknown_role"}}
      before do
        sign_in user
        group = Group.create name: "foo"
        membership = user.memberships.create group_id: group.id
        xhr :post, :create, user_id: user.id, id: membership.id,
          membership: membership_params, format: :json
      end
      it{expect render_template 'error/failed', status: 400}
    end
  end

  describe "DELETE destroy" do
    context "when a user destroyed own membership" do
      before do
        sign_in user
        group = Group.create name: "foo"
        membership = user.memberships.create group_id: group.id
        delete :destroy, user_id: user.id,
          id: membership.id, format: :json
      end
      it{should render_template :destroy}
{'fraction_non_alphanumeric': 0.08930453108535301, 'fraction_numerical': 0.0026343519494204425, 'mean_word_length': 2.697176241480039, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1362493', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1136, 'n_words': 350}