|
128 | 128 | end |
129 | 129 | end |
130 | 130 | end |
| 131 | + |
| 132 | + describe 'creating events with different location types' do |
| 133 | + let(:locale) { I18n.default_locale } |
| 134 | + |
| 135 | + context 'as platform manager', :as_platform_manager do |
| 136 | + it 'creates an event with a simple (name) location' do |
| 137 | + params = { |
| 138 | + event: { |
| 139 | + name: 'Simple Location Event', |
| 140 | + starts_at: 1.day.from_now.iso8601, |
| 141 | + identifier: SecureRandom.uuid, |
| 142 | + privacy: 'public', |
| 143 | + location_attributes: { |
| 144 | + name: 'Community Hall' |
| 145 | + } |
| 146 | + }, |
| 147 | + locale: locale |
| 148 | + } |
| 149 | + |
| 150 | + post better_together.events_path(locale: locale), params: params |
| 151 | + |
| 152 | + expect(response).to have_http_status(:found) |
| 153 | + event = BetterTogether::Event.order(:created_at).last |
| 154 | + expect(event).to be_present |
| 155 | + expect(event.location).to be_present |
| 156 | + expect(event.location.name).to eq('Community Hall') |
| 157 | + expect(event.location.location).to be_nil |
| 158 | + end |
| 159 | + |
| 160 | + it 'creates an event with an Address location' do |
| 161 | + address = create(:better_together_address, privacy: 'public') |
| 162 | + |
| 163 | + params = { |
| 164 | + event: { |
| 165 | + name: 'Address Location Event', |
| 166 | + starts_at: 1.day.from_now.iso8601, |
| 167 | + identifier: SecureRandom.uuid, |
| 168 | + privacy: 'public', |
| 169 | + location_attributes: { |
| 170 | + location_id: address.id, |
| 171 | + location_type: 'BetterTogether::Address' |
| 172 | + } |
| 173 | + }, |
| 174 | + locale: locale |
| 175 | + } |
| 176 | + |
| 177 | + post better_together.events_path(locale: locale), params: params |
| 178 | + |
| 179 | + expect(response).to have_http_status(:found) |
| 180 | + event = BetterTogether::Event.order(:created_at).last |
| 181 | + expect(event).to be_present |
| 182 | + expect(event.location).to be_present |
| 183 | + expect(event.location.location_type).to eq('BetterTogether::Address') |
| 184 | + expect(event.location.address).to be_present |
| 185 | + expect(event.location.address.id).to eq(address.id) |
| 186 | + end |
| 187 | + |
| 188 | + it 'creates an event with a Building location' do |
| 189 | + manager_user = BetterTogether:: User.find_by(email: '[email protected]') || |
| 190 | + create(:better_together_user, :confirmed, :platform_manager, email: '[email protected]') |
| 191 | + building = create(:better_together_infrastructure_building, creator: manager_user.person, privacy: 'private') |
| 192 | + |
| 193 | + params = { |
| 194 | + event: { |
| 195 | + name: 'Building Location Event', |
| 196 | + starts_at: 1.day.from_now.iso8601, |
| 197 | + identifier: SecureRandom.uuid, |
| 198 | + privacy: 'public', |
| 199 | + location_attributes: { |
| 200 | + location_id: building.id, |
| 201 | + location_type: 'BetterTogether::Infrastructure::Building' |
| 202 | + } |
| 203 | + }, |
| 204 | + locale: locale |
| 205 | + } |
| 206 | + |
| 207 | + post better_together.events_path(locale: locale), params: params |
| 208 | + |
| 209 | + expect(response).to have_http_status(:found) |
| 210 | + event = BetterTogether::Event.order(:created_at).last |
| 211 | + expect(event).to be_present |
| 212 | + expect(event.location).to be_present |
| 213 | + expect(event.location.location_type).to eq('BetterTogether::Infrastructure::Building') |
| 214 | + expect(event.location.building).to be_present |
| 215 | + expect(event.location.building.id).to eq(building.id) |
| 216 | + end |
| 217 | + |
| 218 | + it 'creates a draft event with no location assigned' do |
| 219 | + params = { |
| 220 | + event: { |
| 221 | + name: 'Draft Event Without Location', |
| 222 | + identifier: SecureRandom.uuid, |
| 223 | + privacy: 'public' |
| 224 | + # intentionally omit starts_at to keep it a draft and omit location_attributes |
| 225 | + }, |
| 226 | + locale: locale |
| 227 | + } |
| 228 | + |
| 229 | + post better_together.events_path(locale: locale), params: params |
| 230 | + |
| 231 | + expect(response).to have_http_status(:found) |
| 232 | + event = BetterTogether::Event.order(:created_at).last |
| 233 | + expect(event).to be_present |
| 234 | + expect(event.starts_at).to be_nil |
| 235 | + expect(event).to be_draft |
| 236 | + expect(event.location).to be_nil |
| 237 | + end |
| 238 | + end |
| 239 | + end |
131 | 240 | end |
0 commit comments