Commit 808e0e0
Changed files (5)
app
models
db
spec
controllers
app/models/gym.rb
@@ -1,5 +1,5 @@
-class Gym
- # name, address, latitude, longitude
+class Gym < ActiveRecord::Base
def self.closest_to(user)
+ all
end
end
db/migrate/20160430041813_create_gyms.rb
@@ -0,0 +1,14 @@
+class CreateGyms < ActiveRecord::Migration
+ def change
+ create_table :gyms, id: :uuid do |t|
+ t.string :name, null: false
+ t.string :address
+ t.string :city
+ t.string :state
+ t.string :country
+ t.decimal :latitude, precision: 10, scale: 6
+ t.decimal :longitude, precision: 10, scale: 6
+ t.timestamps null: false
+ end
+ end
+end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20151115190853) do
+ActiveRecord::Schema.define(version: 20160430041813) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -41,6 +41,18 @@ ActiveRecord::Schema.define(version: 20151115190853) do
t.datetime "updated_at", null: false
end
+ create_table "gyms", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t|
+ t.string "name", null: false
+ t.string "address"
+ t.string "city"
+ t.string "state"
+ t.string "country"
+ t.decimal "latitude", precision: 10, scale: 6
+ t.decimal "longitude", precision: 10, scale: 6
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
create_table "profiles", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t|
t.uuid "user_id", null: false
t.integer "gender"
spec/controllers/gyms_controller_spec.rb
@@ -8,14 +8,10 @@ describe GymsController do
end
describe "#index" do
- let(:sait) { double }
- let(:world_health) { double }
+ let(:sait) { create(:gym, name: 'sait') }
+ let(:world_health) { create(:gym, name: 'world health') }
it 'returns a list of gyms' do
- allow(Gym).to receive(:closest_to).
- with(user).
- and_return([sait, world_health])
-
get :index
expect(assigns(:gyms)).to match_array([sait, world_health])
spec/factories.rb
@@ -53,4 +53,11 @@ FactoryGirl.define do
]}
end
end
+ factory :gym do
+ name { FFaker::Internet.user_name }
+ address { FFaker::Address.street_address }
+ city { FFaker::AddressCA.city }
+ state { FFaker::AddressCA.city }
+ country { FFaker::Address.country }
+ end
end