<repo_name>lailazaki/yodaish<file_sep>/app/models/page.rb
class Page < ActiveRecord::Base

  def self.yoda(quote)
	  quote ||= "Lets Speak Some Yoda" 
	  response = Unirest.get "https://yoda.p.mashape.com/yoda?sentence=#{quote}",
	  headers:{
	    "X-Mashape-Key" => "<KEY>",
	    "Accept" => "text/plain"
	  }
  end
  
end    


<file_sep>/spec/requests/authentication_pages_spec.rb
require 'rails_helper'

describe "Authentication" do
  subject { page }

  describe "signin page" do
    before { visit signin_path }

    it { should have_title('Sign In') }
    it { should have_content('Sign In') }

    describe 'signin process' do
      let(:submit) { 'Sign In' }
      let(:user) { User.create(name: "<NAME>", email: "<EMAIL>",
                            password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }
      context 'valid information' do
        before { sign_in user }

        it { should have_title(user.name) }
      end
      context 'invalid information' do
      end
    end
    
  end
end<file_sep>/spec/requests/user_pages_spec.rb
require 'rails_helper'

describe 'user pages' do
  subject { page }

  describe 'index' do
    User.destroy_all
    let(:user1) { User.create(name: "<NAME>", email: "<EMAIL>",
                        password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }
    let(:user2) { User.create(name: "<NAME>", email: "<EMAIL>",
                        password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }

    before { visit users_path }

    it { should have_title('All Users') }
    it { should have_selector('h1', text: 'All Users') }

    it "lists each user" do
      User.all.each do |user|
        expect(page).to have_selector('li', text: user.id)
      end
    end

    describe 'delete links' do
      let!(:user1) { User.create(name: "<NAME>", email: "<EMAIL>",
                          password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }
      let!(:user2) { User.create(name: "<NAME>", email: "<EMAIL>",
                          password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }

      before { visit users_path }
      it { should have_link('delete', href: user_path(User.first)) }

      describe 'after clicking delete' do
        before { click_link('delete', match: :first) }
        it { should_not have_content('Laila Zaki') }
      end
    end
  end

  describe 'show' do
    let(:user) { User.create(name: "<NAME>", email: "<EMAIL>",
                        password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }

    before { visit user_path(user.id) }

    it { should have_title(user.name) }
    it { should have_selector('h1', text: user.name) }
  end

  describe 'new user page' do
    before { visit signup_path }

    it { should have_title('Sign Up') }
    it { should have_selector('h1', 'Sign Up') }

    describe 'create user' do
      let(:submit) { 'Save' }

      context 'valid information' do
        before do
          # fill in all necessary info in the fields
          fill_in 'Name',             with: '<NAME>'
          fill_in 'Email',            with: '<EMAIL>'
          fill_in 'Password',         with: '<PASSWORD>'
          fill_in 'Confirm password', with: '<PASSWORD>'
        end

        it 'creates user' do
          expect { click_button submit }.to change(User, :count).by(1)
        end

        describe 'after saving' do

          before { click_button submit }

          it { should have_title('Laila Zaki') }
        end
      end

      context 'invalid information' do
        it 'does not create user' do
          expect { click_button submit }.not_to change(User, :count)
        end

        describe 'after submission' do
          before { click_button submit }

          it { should have_title('Sign Up') }
          it { should have_content('error') }
        end
      end
    end
  end

  describe 'edit user page' do
    let(:user_for_edit) { User.create(name: "<NAME>", email: "<EMAIL>",
                        password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }

    before { visit edit_user_path(user_for_edit.id) }

    it { should have_title('Edit Profile') }
    it { should have_selector('h1', 'Edit Profile') }

    describe 'update user' do
      let(:submit) { 'Save' }

      context 'valid information' do

        before do
          fill_in "Name", with: "<NAME>"
          click_button submit
        end

        describe 'after saving changes' do
          it { should have_title('<NAME>') }
          specify { expect(user_for_edit.reload.name).to eq('<NAME>') }
        end
      end

      context 'invalid information' do
        before do
          fill_in "Name", with: " "
          click_button submit
        end
        describe 'after submission' do
          it { should have_title('Edit Profile') }
          it { should have_content('error') }
        end
      end
    end
  end
end<file_sep>/spec/controllers/pages_controller_spec.rb
require 'rails_helper'

describe PagesController, type: :controller do
  describe '#index' do
    it 'renders index' do
      get :index
      expect(response).to render_template(:index)
    end
  end
describe '#random' do
    it 'renders random' do
      get :random
      expect(response).to render_template(:random)
    end
  end
  describe '#about' do
    it 'renders about' do
      get :about
      expect(response).to render_template(:about)
    end
  end
end<file_sep>/config/routes.rb
Rails.application.routes.draw do


  root 'pages#index'
  
  resources :pages
  resources :users, except:[:new]
  resources :sessions, only:[:create]

  get '/', 	to: 'pages#index'
  get '/random' , to: 'pages#random'
  get '/about', to: 'pages#about'

  get '/signup', 			to: 'users#new'
  get '/signin', 			to: 'sessions#new'
  delete '/signout', 	to: 'sessions#destroy'



end
<file_sep>/app/controllers/pages_controller.rb
class PagesController < ApplicationController
  

  def index
    @quote = Page.yoda(params[:quote])
  end

  def random
  	@active = 'random'
  	render :layout => false
  end

  def about
  	@active = 'about'
    render :layout => false
  end

end
