blob: b407cd8662668eaef52561a7cc6d08faca6301b5 (
plain)
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
|
require 'spec_helper'
RSpec.describe Chouette::Route, :type => :model do
subject(:route){ create :route }
context "metadatas" do
it "should be empty at first" do
expect(Chouette::Route.has_metadata?).to be_truthy
expect(route.has_metadata?).to be_truthy
expect(route.metadata.creator_username).to be_nil
expect(route.metadata.modifier_username).to be_nil
end
context "once set" do
it "should set the correct values" do
Timecop.freeze(Time.now) do
route.metadata.creator_username = "john.doe"
route.save!
id = route.id
route = Chouette::Route.find id
expect(route.metadata.creator_username).to eq "john.doe"
expect(route.metadata.creator_username_updated_at.strftime('%Y-%m-%d %H:%M:%S.%3N')).to eq Time.now.strftime('%Y-%m-%d %H:%M:%S.%3N')
end
end
end
describe "#merge_metadata_from" do
let(:source){ create :route }
let(:metadata){ target.merge_metadata_from(source).metadata }
let(:target){ create :route }
before do
target.metadata.creator_username = "john"
target.metadata.modifier_username = "john"
end
context "when the source has no metadata" do
it "should do nothing" do
expect(metadata.creator_username).to eq "john"
expect(metadata.modifier_username).to eq "john"
end
end
context "when the source has older metadata" do
before do
source.metadata.creator_username = "jane"
source.metadata.modifier_username = "jane"
source.metadata.creator_username_updated_at = 1.month.ago
source.metadata.modifier_username_updated_at = 1.month.ago
end
it "should do nothing" do
expect(metadata.creator_username).to eq "john"
expect(metadata.modifier_username).to eq "john"
end
end
context "when the source has new metadata" do
before do
source.metadata.creator_username = "jane"
source.metadata.modifier_username = "jane"
target.metadata.creator_username_updated_at = 1.month.ago
target.metadata.modifier_username_updated_at = 1.month.ago
end
it "should update metadata" do
expect(metadata.creator_username).to eq "jane"
expect(metadata.modifier_username).to eq "jane"
end
end
end
end
end
|