Sha256: 83e1604e9877dcc73c9d2c6bf91ac4a35e8dd46f4e3c90f61352bd0d6ab31bcb

Contents?: true

Size: 1.59 KB

Versions: 26

Compression:

Stored size: 1.59 KB

Contents

class Zendesk2::Client
  class Real
    def create_membership(params={})
      require_parameters(params, "user_id", "organization_id")

      user_id = params["user_id"]

      request(
        :body   => {"organization_membership" => params },
        :method => :post,
        :path   => "/users/#{user_id}/organization_memberships.json",
      )
    end
  end # Real

  class Mock
    def create_membership(params={})
      require_parameters(params, "user_id", "organization_id")

      user_id         = params["user_id"]
      organization_id = params["organization_id"]

      find!(:users, user_id)
      find!(:organizations, organization_id, error: :invalid, details: { "organization" => [ { "description" => "Organization cannot be blank" } ] })
      if self.data[:memberships].values.find { |m| m["user_id"] == user_id && m["organization_id"] == organization_id }
        error!(:invalid, description: { "user_id" => [ { "description" => "User has already been taken" } ] })
      end

      resource_id = self.class.new_id

      default_membership = false # !self.data[:memberships].values.find { |m| m["user_id"] == user_id && m["default"] }

      resource = {
        "id"              => resource_id,
        "user_id"         => user_id,
        "organization_id" => organization_id,
        "default"         => default_membership,
      }

      self.data[:memberships][resource_id] = resource

      response(
        :method => :post,
        :body   => { "organization_membership" => resource },
        :path   => "/users/#{user_id}/organization_memberships.json",
      )
    end
  end # Mock
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
zendesk2-1.4.2 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.4.1 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.4.0 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.3.3 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.3.2 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.3.1 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.3.0 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.10 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.9 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.7 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.6 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.5 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.4 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.3 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.2 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.1 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.2.0 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.1.3 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.1.2 lib/zendesk2/client/requests/create_membership.rb
zendesk2-1.0.0 lib/zendesk2/client/requests/create_membership.rb