Module: RSpecApi::DSL::Accepts

Included in:
RSpecApi::DSL
Defined in:
lib/rspec-api/dsl/accepts.rb

Instance Method Summary collapse

Instance Method Details

#accepts_callback(callback_parameter) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/rspec-api/dsl/accepts.rb', line 24

def accepts_callback(callback_parameter)
  any_callback = 'a_callback'
  @expectations << {
    query_params: {}.tap{|qp| qp[callback_parameter] = any_callback},
    status_expect: {status: 200},
    body_expect: {callback: any_callback}
  }
end

#accepts_filter(filter_parameter, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec-api/dsl/accepts.rb', line 33

def accepts_filter(filter_parameter, options={})
  value = existing(options[:by])
  @expectations << {
    query_params: {}.tap{|qp| qp[filter_parameter] = value},
    before: create_fixture,
    after: destroy_fixture,
    status_expect: {status: 200},
    body_expect: {filter: options.slice(:by, :comparing_with).merge(value: value)}
  }
end

#accepts_page(page_parameter) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/rspec-api/dsl/accepts.rb', line 5

def accepts_page(page_parameter)
  any_page = 2
  @expectations << {
    query_params: {}.tap{|qp| qp[page_parameter] = any_page},
    status_expect: {status: 200},
    headers_expect: {has_prev_page: true}
  }
end

#accepts_sort(sort_parameter, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/rspec-api/dsl/accepts.rb', line 14

def accepts_sort(sort_parameter, options={})
  @expectations << {
    query_params: {sort: sort_parameter}.merge(options.fetch(:sort_if, {})),
    before: create_fixture,
    after: destroy_fixture,
    status_expect: {status: 200},
    body_expect: {sort: options.slice(:by, :verse)}
  }
end