Files
openfoodnetwork/spec/serializers/admin/customer_serializer_spec.rb
Rob Harrington ddcfe1535a Making TagRule autocomplete available to models other than Customer
Incorporate ng admin.tags module and rails TagController into existing admin.tagRules module + TagRuleController
2016-05-25 08:10:20 +10:00

16 lines
720 B
Ruby

describe Api::Admin::CustomerSerializer do
let(:customer) { create(:customer, tag_list: "one, two, three") }
let!(:tag_rule) { create(:tag_rule, enterprise: customer.enterprise, preferred_customer_tags: "two") }
it "serializes a customer" do
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: customer.enterprise_id))
serializer = Api::Admin::CustomerSerializer.new customer, tag_rule_mapping: tag_rule_mapping
result = JSON.parse(serializer.to_json)
expect(result['email']).to eq customer.email
tags = result['tags']
expect(tags.length).to eq 3
expect(tags[0]).to eq({ "text" => 'one', "rules" => nil })
expect(tags[1]).to eq({ "text" => 'two', "rules" => 1 })
end
end