-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathsite_controller_spec.rb
136 lines (121 loc) · 3.63 KB
/
site_controller_spec.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# frozen_string_literal: true
RSpec.describe SiteController do
fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) }
fab!(:user)
fab!(:group_2) { Fabricate(:group) }
fab!(:user_with_group) { Fabricate(:user, group_ids: [group.id]) }
let!(:anon_ad) do
AdPlugin::HouseAd.create(
name: "anon-ad",
html: "<div>ANON</div>",
visible_to_logged_in_users: false,
visible_to_anons: true,
group_ids: [],
category_ids: [],
)
end
let!(:logged_in_ad) do
AdPlugin::HouseAd.create(
name: "logged-in-ad",
html: "<div>LOGGED IN</div>",
visible_to_logged_in_users: true,
visible_to_anons: false,
group_ids: [],
category_ids: [],
)
end
let!(:logged_in_ad_with_category) do
AdPlugin::HouseAd.create(
name: "logged-in-ad-with-category",
html: "<div>LOGGED IN WITH CATEGORY</div>",
visible_to_logged_in_users: true,
visible_to_anons: false,
group_ids: [group.id],
category_ids: [private_category.id],
)
end
let!(:logged_in_ad_with_group_2) do
AdPlugin::HouseAd.create(
name: "logged-in-ad-with-group",
html: "<div>LOGGED IN WITH GROUP</div>",
visible_to_logged_in_users: true,
visible_to_anons: false,
group_ids: [group_2.id],
category_ids: [],
)
end
let!(:everyone_ad) do
AdPlugin::HouseAd.create(
name: "everyone-ad",
html: "<div>EVERYONE</div>",
visible_to_logged_in_users: true,
visible_to_anons: true,
group_ids: [],
category_ids: [],
)
end
let!(:everyone_group_ad) do
AdPlugin::HouseAd.create(
name: "everyone-group-ad",
html: "<div>EVERYONE</div>",
visible_to_logged_in_users: true,
visible_to_anons: false,
group_ids: [Group::AUTO_GROUPS[:everyone]],
category_ids: [],
)
end
before do
AdPlugin::HouseAdSetting.update(
"topic_list_top",
"logged-in-ad|anon-ad|everyone-ad|logged-in-ad-with-category|logged-in-ad-with-group|everyone-group-ad",
)
end
describe "#site" do
context "when logged in" do
it "only includes ads that are visible to logged in users" do
sign_in(user)
get "/site.json"
# excluded logged_in_ad_with_group_2 and logged_in_ad_with_category
expect(response.parsed_body["house_creatives"]["creatives"].keys).to contain_exactly(
"logged-in-ad",
"everyone-group-ad",
"everyone-ad",
)
end
it "includes ads that are within the logged in user's category permissions" do
sign_in(user_with_group)
get "/site.json"
expect(response.parsed_body["house_creatives"]["creatives"].keys).to contain_exactly(
"logged-in-ad",
"everyone-group-ad",
"logged-in-ad-with-category",
"everyone-ad",
)
end
end
context "when anonymous" do
it "only includes ads that are visible to anonymous users" do
get "/site.json"
# excludes everyone_group_ad
expect(response.parsed_body["house_creatives"]["creatives"].keys).to contain_exactly(
"anon-ad",
"everyone-ad",
)
end
it "invalidates cache when an ad is updated" do
get "/site.json"
expect(response.parsed_body["house_creatives"]["creatives"].keys).to contain_exactly(
"anon-ad",
"everyone-ad",
)
anon_ad.visible_to_anons = false
anon_ad.save
get "/site.json"
expect(response.parsed_body["house_creatives"]["creatives"].keys).to contain_exactly(
"everyone-ad",
)
end
end
end
end