Giter Club home page Giter Club logo

rails-contacts's Introduction

Rails Model Methods

This app demonstrates the pitfalls of implementing fat controllers.

Goal

  • Move code that belongs in the model out of the controller.

How you'll get there

  • You'll get the model spec examples to pass
  • Use ActiveRecord methods to accomplish this.
  • You'll also need to create a migration! :shipit:

Getting Started

After you've cloned this repo

  • From the app's root directory, run:
$ bundle install
$ rake db:create
$ rake db:migrate
$ rake db:seed
$ rake db:test:prepare

rake db:test:prepare just checks to see if there are any pending migrations for our test database, and make sure our test environment and development environment are in-sync when we run our tests.

  • Take a look at the file db/seeds.rb to see how we are seeding the database

Then get the specs to pass for

Person.all_email_domains

  • Note: Do this First

  • You'll need to create a migration that will add the domain_namefield as a string to the people table

    Pro-tip: Make sure to run your migrations, and prepare the test database

  • Populate all instances of People with the appropriate domain_name

    Hint: What current property of people has data you could draw from?

    Hint: How could you modify that data to only capture the appropriate domain_name?

    Look at the current implementations in the person_controller.rb

  • To get a quick refresher on how to generate a migration, check out the guides

Person.find_all_with_email_domain

  • Your method should take one argument representing a domain.
  • The return of the method should be all instances of Person that match that given domain, or return everyone if passed All

Bonus

Research Rails Validations and Active Record Callbacks to look into how to control for user input

  • Make all the pending tests active by removing the x from xit on lines 60, 64, and 76 in spec/models/person_spec.rb

  • Get the appropriate tests to pass by defining sanitize_email and generate_domain_name as instance methods.

    • sanitize_email should make all emails a uniform case
    • generate_domain_name will add a domain_name to a person if they are created without one
  • Use these methods as Active Record callbacks.

Resources used

Thanks http://www.briandunning.com/sample-data/ for the sample data!

rails-contacts's People

Contributors

zealoushacker avatar nolds9 avatar

Watchers

James Cloos avatar Michael L Parks avatar

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.