Sha256: d301f29d911dba9bd377199633c51cbda6d54bea5ecda1fc24d479ebc83f587d

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

class Zendesk2::Client
  class Real
    def create_user(params={})
      request(
        :body   => {"user" => params},
        :method => :post,
        :path   => "/users.json",
      )
    end
  end # Real

  class Mock
    def create_user(params={})
      identity = self.class.new_id

      record = {
        "id"         => identity,
        "url"        => url_for("/users/#{identity}.json"),
        "created_at" => Time.now.iso8601,
        "updated_at" => Time.now.iso8601,
        "active"     => true,
      }.merge(params)

      path = "/users.json"
      if record["email"] && self.data[:users].find{|k,u| u["email"] == record["email"] && k != identity}
        response(
          :method => :put,
          :path   => path,
          :status => 422,
          :body   => {
            "error"       => "RecordInvalid",
            "description" => "Record validation errors", "details" => {
              "email"       => [ {
                "type"        => "#{record["email"]} is already being used by another user",
                "description" => "Email: #{record["email"]} is already being used by another user"
              } ]
            }
          }
        )
      else

        self.data[:users][identity]= record

        response(
          :method => :post,
          :body   => {"user" => record},
          :path   => path,
        )
      end
    end
  end # Mock
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
zendesk2-0.0.18 lib/zendesk2/client/requests/create_user.rb
zendesk2-0.0.17 lib/zendesk2/client/requests/create_user.rb
zendesk2-0.0.16 lib/zendesk2/client/requests/create_user.rb
zendesk2-0.0.15 lib/zendesk2/client/requests/create_user.rb
zendesk2-0.0.14 lib/zendesk2/client/requests/create_user.rb