github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/tests/system/lib/account.rb (about) 1 class Account 2 include Model 3 4 attr_reader :name, :log 5 6 def self.doctype 7 "io.cozy.accounts" 8 end 9 10 def initialize(opts = {}) 11 @couch_id = opts[:id] 12 @name = (opts[:name] || Faker::TvShows::DrWho.character).gsub(/[^A-Za-z0-9]/, '_') 13 @log = opts[:log] || "#{Helpers.current_dir}/account_#{@name}.log" 14 @aggregator = opts[:aggregator] 15 @failure = opts[:failure] 16 @type = opts[:type] 17 @auth = opts[:auth] 18 end 19 20 def as_json 21 json = { 22 name: @name, 23 data: { 24 log: @log, 25 failure: @failure 26 }, 27 account_type: @type, 28 auth: @auth 29 }.compact 30 if @aggregator 31 json[:relationships] = { 32 data: { 33 _id: @aggregator.couch_id, 34 _type: @aggregator.doctype 35 } 36 } 37 end 38 json 39 end 40 end