Skip to content

Commit 0acc1c2

Browse files
committed
Implement tests to verify a deeply frozen URI doesn't mutate instance variables unnecessarily
1 parent a57778a commit 0acc1c2

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

spec/addressable/uri_spec.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,75 @@ def to_s
999999
end
10001000
end
10011001

1002+
describe Addressable::URI, "when normalized and then deeply frozen" do
1003+
before do
1004+
@uri = Addressable::URI.parse(
1005+
"http://user:password@example.com:8080/path?query=value#fragment"
1006+
).normalize!
1007+
1008+
@uri.instance_variables.each do |var|
1009+
@uri.instance_variable_set(
1010+
var, @uri.instance_variable_get(var).freeze
1011+
)
1012+
end
1013+
1014+
@uri.freeze
1015+
end
1016+
1017+
it "#normalized_scheme should not error" do
1018+
expect { @uri.normalized_scheme }.not_to raise_error
1019+
end
1020+
1021+
it "#normalized_user should not error" do
1022+
expect { @uri.normalized_user }.not_to raise_error
1023+
end
1024+
1025+
it "#normalized_password should not error" do
1026+
expect { @uri.normalized_password }.not_to raise_error
1027+
end
1028+
1029+
it "#normalized_userinfo should not error" do
1030+
p @uri.normalized_userinfo
1031+
expect { @uri.normalized_userinfo }.not_to raise_error
1032+
end
1033+
1034+
it "#normalized_host should not error" do
1035+
expect {@uri.normalized_host}.not_to raise_error
1036+
end
1037+
1038+
it "#normalized_authority should not error" do
1039+
expect { @uri.normalized_authority }.not_to raise_error
1040+
end
1041+
1042+
it "#normalized_port should not error" do
1043+
expect { @uri.normalized_port }.not_to raise_error
1044+
end
1045+
1046+
it "#normalized_site should not error" do
1047+
expect { @uri.normalized_site }.not_to raise_error
1048+
end
1049+
1050+
it "#normalized_path should not error" do
1051+
expect { @uri.normalized_path }.not_to raise_error
1052+
end
1053+
1054+
it "#normalized_query should not error" do
1055+
expect { @uri.normalized_query }.not_to raise_error
1056+
end
1057+
1058+
it "#normalized_fragment should not error" do
1059+
expect { @uri.normalized_fragment }.not_to raise_error
1060+
end
1061+
1062+
it "should be frozen" do
1063+
expect(@uri).to be_frozen
1064+
end
1065+
1066+
it "should not allow destructive operations" do
1067+
expect { @uri.normalize! }.to raise_error(FrozenError)
1068+
end
1069+
end
1070+
10021071
describe Addressable::URI, "when created from string components" do
10031072
before do
10041073
@uri = Addressable::URI.new(

0 commit comments

Comments
 (0)