test/unit/test_permissions.rb in spontaneous-0.2.0.beta4 vs test/unit/test_permissions.rb in spontaneous-0.2.0.beta5

- old
+ new

@@ -407,11 +407,11 @@ end it "be guaranteed unique" do Permissions.stubs(:random_string).returns("xxxx") key1 = Permissions::AccessKey.create() - lambda { Permissions::AccessKey.create() }.must_raise(Sequel::DatabaseError) + lambda { Permissions::AccessKey.create() }.must_raise(Sequel::UniqueConstraintViolation) end it "have a creation date" do key1 = Permissions::AccessKey.create key1.created_at.to_i.must_equal @now.to_i @@ -782,44 +782,48 @@ ] # end end it "only list allowed types addable by the user" do + allowed_type_names = Proc.new do |a| + a[:type] + end + expected = [ ["editor_level", ["D", "C"]], ["admin_level", ["C"]], ["root_level", ["C"]], ["mixed_level", ["C"]], ["default_level", ["C"]] ] - C.export[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected + C.export[:boxes].map { |b| [b[:name], b[:allowed_types].map(&allowed_type_names)] }.must_equal expected # Permissions.with_user(@root) do - C.export(@root)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected + C.export(@root)[:boxes].map { |b| [b[:name], b[:allowed_types].map(&allowed_type_names)] }.must_equal expected # end # Permissions.with_user(@visitor) do expected = [ ["default_level", []] ] - C.export(@visitor)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected + C.export(@visitor)[:boxes].map { |b| [b[:name], b[:allowed_types].map(&allowed_type_names)] }.must_equal expected # end # Permissions.with_user(@editor) do expected = [ ["editor_level", ["D"]], ["mixed_level", []], ["default_level", ["C"]] ] - C.export(@editor)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected + C.export(@editor)[:boxes].map { |b| [b[:name], b[:allowed_types].map(&allowed_type_names)] }.must_equal expected # end # Permissions.with_user(@admin) do expected = [ ["editor_level", ["D", "C"]], ["admin_level", ["C"]], ["mixed_level", []], ["default_level", ["C"]] ] - C.export(@admin)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected + C.export(@admin)[:boxes].map { |b| [b[:name], b[:allowed_types].map(&allowed_type_names)] }.must_equal expected # end end it "serialise only things in instance viewable by the current user" do expected = [ @@ -888,10 +892,10 @@ # end end it "determine what fields are visible in the exoported schema" do - schema = Site.schema.export(@editor) + schema = @site.schema.export(@editor) c_schema = schema["C"] c_schema[:fields].map { |f| f[:name] }.must_equal %w(editor_level mixed_level default_level) c_schema[:boxes].map { |b| b[:name] }.must_equal %w(editor_level mixed_level default_level) end end