Commit e41e39c

mo <mo.khan@gmail.com>
2018-05-11 22:28:23
implement map_from
1 parent fc06c0a
Changed files (2)
lib/del/user.rb
@@ -14,5 +14,9 @@ module Del
     def to_s
       YAML.dump(attributes)
     end
+
+    def self.map_from(attributes)
+      new(attributes[:id], attributes)
+    end
   end
 end
spec/user_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+RSpec.describe Del::User do
+  describe ".map_from" do
+    subject { described_class }
+    let(:attributes) { { id: SecureRandom.uuid } }
+
+    it 'returns a new user' do
+      result = subject.map_from(attributes)
+      expect(result).to be_instance_of(described_class)
+      expect(result.jid).to eql(attributes[:id])
+      expect(result.attributes).to eql(attributes)
+    end
+  end
+end