|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe UserMailerHelper, type: :helper do |
| 4 | + before(:each) do |
| 5 | + @app_configs = double(department_name: 'dept', terms_of_service: 'tos') |
| 6 | + @reservation = double(id: 1, reserver: double(name: 'name'), |
| 7 | + equipment_model: double(name: 'em', late_fee: 100, |
| 8 | + replacement_fee: 200), |
| 9 | + start_date: Time.zone.today, |
| 10 | + due_date: Time.zone.today + 1.day) |
| 11 | + end |
| 12 | + |
| 13 | + context '.replace_variables' do |
| 14 | + it 'returns an empty string when no body is passed' do |
| 15 | + expect(replace_variables(nil)).to eq('') |
| 16 | + end |
| 17 | + |
| 18 | + it 'replaces @user@ with the reserver name' do |
| 19 | + expect(replace_variables('@user@')).to eq(@reservation.reserver.name) |
| 20 | + end |
| 21 | + |
| 22 | + it 'replaces @reservation_id@ with the reservation id' do |
| 23 | + expect(replace_variables('@reservation_id@')).to eq(@reservation.id.to_s) |
| 24 | + end |
| 25 | + |
| 26 | + it 'replaces @department_name@ with the department name' do |
| 27 | + expect(replace_variables('@department_name@')).to \ |
| 28 | + eq(@app_configs.department_name) |
| 29 | + end |
| 30 | + |
| 31 | + it 'replaces @equipment_list@ with the equipment model name' do |
| 32 | + expect(replace_variables('@equipment_list@')).to \ |
| 33 | + eq(@reservation.equipment_model.name) |
| 34 | + end |
| 35 | + |
| 36 | + it 'replaces @return_date@ with the due date' do |
| 37 | + expect(replace_variables('@return_date@')).to \ |
| 38 | + eq(@reservation.due_date.to_s(:long)) |
| 39 | + end |
| 40 | + |
| 41 | + it 'replaces @start_date@ with the start date' do |
| 42 | + expect(replace_variables('@start_date@')).to \ |
| 43 | + eq(@reservation.start_date.to_s(:long)) |
| 44 | + end |
| 45 | + |
| 46 | + it 'replaces @late_fee@ with the equipment model late fee rate' do |
| 47 | + expect(replace_variables('@late_fee@')).to \ |
| 48 | + eq(number_to_currency(@reservation.equipment_model.late_fee)) |
| 49 | + end |
| 50 | + |
| 51 | + it 'replaces @replacement_fee@ with the equipment model replacement fee' do |
| 52 | + expect(replace_variables('@replacement_fee@')).to \ |
| 53 | + eq(number_to_currency(@reservation.equipment_model.replacement_fee)) |
| 54 | + end |
| 55 | + |
| 56 | + it 'replaces @tos@ with the terms of service' do |
| 57 | + expect(replace_variables('@tos@')).to eq(@app_configs.terms_of_service) |
| 58 | + end |
| 59 | + end |
| 60 | +end |
0 commit comments