api_test.rb
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_relative '../../../../test/api/test_helper'
class ApiTest < ActiveSupport::TestCase
def setup
create_and_activate_user
login_api
environment.enable_plugin(StatisticsPlugin)
end
AVAILABLE_ATTRIBUTES = StatisticsBlock::USER_COUNTERS + StatisticsBlock::COMMUNITY_COUNTERS + StatisticsBlock::ENTERPRISE_COUNTERS
AVAILABLE_ATTRIBUTES.map do |counter_attr|
counter_method = counter_attr.to_s.gsub('_counter','').pluralize.to_sym
define_method "test_should_return_#{counter_method}_attribute_in_statistics_block_if_#{counter_attr} is true" do
person.boxes.destroy_all
box = Box.create!(:owner => person)
block = StatisticsBlock.create!(:box_id => box.id)
block.send("#{counter_attr}=", true)
block.save
get "/api/v1/profiles/#{person.id}/boxes?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_not_nil json["boxes"].first['blocks'].first[counter_method.to_s]
end
define_method "test_should_not_return_#{counter_method}_attribute_in_statistics_block_if_#{counter_attr} is false" do
person.boxes.destroy_all
box = Box.create!(:owner => person)
block = StatisticsBlock.create!(:box_id => box.id)
block.send("#{counter_attr}=", false)
block.save
get "/api/v1/profiles/#{person.id}/boxes?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_nil json["boxes"].first['blocks'].first[counter_method]
end
end
end