Git Product home page Git Product logo

apartment-app-f-rivers's Introduction

Apartment App

This app has been created for you to mimic the feeling of entering into a developer role where there is established code that you have not created. This Apartment application has a few features that have been created for you and some key items that have been left totally untouched. Part of your job as a developer is to be able to pick up code that has already been created, understand what is going on with it, and continue the development of that code.

๐Ÿ‘จโ€๐Ÿ’ป How We Got Here

$ rails new apartment-app -d postgresql -T
$ cd apartment-app
$ rails db:create
$ bundle add rspec-rails
$ rails generate rspec:install
$ bundle add webpacker
$ bundle add react-rails
$ rails webpacker:install
$ rails webpacker:install:react
$ yarn add @babel/preset-react
$ yarn add @rails/activestorage
$ yarn add @rails/ujs
$ rails generate react:install
$ rails generate react:component App
$ bundle add devise
$ rails generate devise:install
$ rails generate devise User
$ rails db:migrate
$ rails generate controller Home

๐Ÿ›  Configurations

Devise Config

config/environments/development.rb

This line added:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

config/initializers/devise.rb

# This line replaced:
config.sign_out_via = :delete
# With this line:
config.sign_out_via = :get

File added in app/views/home called index.html.erb app/views/home/index.html.erb

<%= react_component 'App', {
  logged_in: user_signed_in?,
  current_user: current_user,
  new_user_route: new_user_registration_path,
  sign_in_route: new_user_session_path,
  sign_out_route: destroy_user_session_path
} %>

React in Rails Config

app/views/layouts/application.html.erb

# This line replaced:
<%= javascript_importmap_tags %>
# With this line:
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

config/routes.rb

# These lines added:
get '*path', to: 'home#index', constraints: ->(request){ request.format.html? }
root 'home#index'

React Routing Config

app/javascript/components/App.js

import {
  BrowserRouter as  Router,
  Route,
  Switch
} from 'react-router-dom'

Reactstrap Config

bundle add bootstrap
mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss
yarn add reactstrap

app/assets/stylesheets/application.scss

@import 'bootstrap';

โšก๏ธ Getting Started

Once you're able to clone the repository, within the root of the project directory, run:

bundle 
yarn
rails db:setup

๐Ÿ Start the App

rails s

See what is available already in the application.

  • What can a USER do?

    • Sign in/out
  • What views (pages, components) are available?

    • See a home, Edit, Index, New, and Show page

๐Ÿก Apartment Resource ย 

The Devise User model is going to have an association with the Apartment model. In this situation, the User will have many apartments and the Apartments will belong to a User.

rails generate resource Apartment street:string city:string state:string manager:string email:string price:string bedrooms:integer bathrooms:integer pets:string image:text user_id:integer
rails db:migrate

User and Apartment Associations

The Apartments will belong to a User and a User will have many apartments.

app/models/apartment.rb

class Apartment < ApplicationRecord
  belongs_to :user
end

app/models/user.rb

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  has_many :apartments
end

๐Ÿš— Testing

To run the existing testing suite, run:

yarn jest
rspec spec/

Apartment Data Specs

Part of your responsibility will be to build out robust tests both for models and for requests. Tests you will need are:

REQUEST:

  • to ensure a user can see all apartments
  • to ensure a user can see all apartments that belong to them
  • to ensure a user can make a new apartment
  • to ensure a user can update an apartment
  • to ensure a user can remove an apartment
  • to ensure a user cannot make a new apartment with nil values
  • to ensure an error will be thrown if an unregistered user tried to make an apartment
  • to ensure an error will be thrown if a user tries to edit an apartment that doesn't belong to them
  • to ensure an error will be thrown if a user tries to delete an apartment that doesn't belong to them

MODELS:

  • to ensure apartment is valid
  • to ensure a user cannot make a new apartment with nil values
  • to ensure a user cannot make a new apartment that already exists in the database
  • to ensure a user cannot update an apartment with nil values
  • to ensure a user cannot update another user's apartment

The following code is a mock and does not work but is here to get your started.

require 'rails_helper'

RSpec.describe "Apartments", type: :request do
  describe "GET /index" do
    it 'returns a list of apartments' do
    
      user = User.where(email: '[email protected]').first_or_create(password: '12345678', password_confirmation: '12345678')

      user.apartments.create(
        street: string,
        city: string,
        state: string,
        manager: string,
        email: string, 
        price: string, 
        bedrooms: integer, 
        bathrooms: integer, 
        pets: string,
        image: text
      )

      get '/apartments'

      apartments = JSON.parse(response.body)
      expect(response).to have_http_status(200)
      expect(apartments.length).to eq(1)
    end
  end
end

apartment-app-f-rivers's People

Contributors

f-rivers avatar github-classroom[bot] avatar

Forkers

f-rivers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.