Sha256: e7824307cdba6aa6cac2c9daaec75895f5c4a248928f1d34713fb6dcf48f1215

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 KB

Contents

names = [
  'X-Wing',
  'Y-Wing',
  'A-Wing',
  'Millenium Falcon',
  'Home One',
  'TIE Fighter',
  'TIE Interceptor',
  'Executor',
]

## Set up "Bases" in ActiveRecord
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

ActiveRecord::Schema.define do
  self.verbose = false
  create_table :bases do |t|
    t.column :name, :string
    t.column :planet, :string
    t.column :faction_id, :integer
  end
end

class Base < ActiveRecord::Base
end

Base.create!(name: "Yavin", planet: "Yavin 4", faction_id: 1)
Base.create!(name: "Echo Base", planet: "Hoth", faction_id: 1)
Base.create!(name: "Death Star", planet: nil, faction_id: 2)
Base.create!(name: "Shield Generator", planet: "Endor", faction_id: 2)
Base.create!(name: "Headquarters", planet: "Coruscant", faction_id: 2)

rebels  = OpenStruct.new({
  id: '1',
  name: 'Alliance to Restore the Republic',
  ships:  ['1', '2', '3', '4', '5'],
  bases: Base.where(faction_id: 1),
  basesClone: Base.where(faction_id: 1),
})


empire = OpenStruct.new({
  id: '2',
  name: 'Galactic Empire',
  ships: ['6', '7', '8'],
  bases: Base.where(faction_id: 2),
  basesClone: Base.where(faction_id: 2),
})

STAR_WARS_DATA = {
  "Faction" => {
    "1" => rebels,
    "2" => empire,
  },
  "Ship" => names.each_with_index.reduce({}) do |memo, (name, idx)|
    id = (idx + 1).to_s
    memo[id] = OpenStruct.new(name: name, id: id)
    memo
  end,
  "Base" => Hash.new { |h, k| h[k] = Base.find(k) }
}

def STAR_WARS_DATA.create_ship(name, faction_id)
  new_id = (self["Ship"].keys.map(&:to_i).max + 1).to_s
  new_ship = OpenStruct.new(id: new_id, name: name)
  self["Ship"][new_id] = new_ship
  self["Faction"][faction_id]["ships"] << new_id
  new_ship
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-relay-0.10.0 spec/support/star_wars_data.rb
graphql-relay-0.9.5 spec/support/star_wars_data.rb
graphql-relay-0.9.4 spec/support/star_wars_data.rb
graphql-relay-0.9.2 spec/support/star_wars_data.rb
graphql-relay-0.9.1 spec/support/star_wars_data.rb
graphql-relay-0.9.0 spec/support/star_wars_data.rb
graphql-relay-0.8.1 spec/support/star_wars_data.rb