diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..050c9d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +!/log/.keep +/tmp diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..c1026d2 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.3.1 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..229da7b --- /dev/null +++ b/Gemfile @@ -0,0 +1,57 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.2.1' +gem 'faker' + +# Use sqlite3 as the database for Active Record +group :production do + gem 'pg', '~> 0.18.4' +end +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# Use CoffeeScript for .coffee assets and views +gem 'coffee-rails', '~> 4.1.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# bundle exec rake doc:rails generates the API under doc/api. +gem 'sdoc', '~> 0.4.0', group: :doc + +gem 'bootstrap-sass', '~> 3.2.0' + +gem 'autoprefixer-rails' + +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +group :development do + gem 'web-console', '~> 2.0' +end + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug' + gem 'rspec-rails', '~> 3.6' + gem 'capybara', '~> 2.4.4' + gem 'pry' + gem 'spring' + gem 'factory_girl_rails' + gem 'shoulda', '~> 3.5' + gem 'sqlite3', '~> 1.3', '>= 1.3.11' +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..57e0c26 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,229 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.1) + actionpack (= 4.2.1) + actionview (= 4.2.1) + activejob (= 4.2.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.1) + actionview (= 4.2.1) + activesupport (= 4.2.1) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.1) + actionview (4.2.1) + activesupport (= 4.2.1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.1) + activejob (4.2.1) + activesupport (= 4.2.1) + globalid (>= 0.3.0) + activemodel (4.2.1) + activesupport (= 4.2.1) + builder (~> 3.1) + activerecord (4.2.1) + activemodel (= 4.2.1) + activesupport (= 4.2.1) + arel (~> 6.0) + activesupport (4.2.1) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.4) + autoprefixer-rails (7.1.5) + execjs + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + bootstrap-sass (3.2.0.2) + sass (~> 3.2) + builder (3.2.3) + byebug (9.1.0) + capybara (2.4.4) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + coderay (1.1.2) + coffee-rails (4.1.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.1.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crass (1.0.2) + debug_inspector (0.0.3) + diff-lcs (1.3) + erubis (2.7.0) + execjs (2.7.0) + factory_girl (4.8.1) + activesupport (>= 3.0.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) + railties (>= 3.0.0) + faker (1.8.4) + i18n (~> 0.5) + ffi (1.9.18) + globalid (0.4.0) + activesupport (>= 4.2.0) + i18n (0.8.6) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (1.8.6) + loofah (2.1.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.6.6) + mime-types (>= 1.16, < 4) + method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.3.0) + minitest (5.10.3) + multi_json (1.12.2) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + pg (0.18.4) + pry (0.11.1) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + rack (1.6.8) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.1) + actionmailer (= 4.2.1) + actionpack (= 4.2.1) + actionview (= 4.2.1) + activejob (= 4.2.1) + activemodel (= 4.2.1) + activerecord (= 4.2.1) + activesupport (= 4.2.1) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.1) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.8) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.1) + actionpack (= 4.2.1) + activesupport (= 4.2.1) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.1.0) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rdoc (4.3.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-rails (3.6.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + sass (3.5.2) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + sdoc (0.4.2) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) + shoulda (3.5.0) + shoulda-context (~> 1.0, >= 1.0.1) + shoulda-matchers (>= 1.4.1, < 3.0) + shoulda-context (1.2.2) + shoulda-matchers (2.8.0) + activesupport (>= 3.0.0) + spring (2.0.2) + activesupport (>= 4.2) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.3) + tzinfo (1.2.3) + thread_safe (~> 0.1) + uglifier (3.2.0) + execjs (>= 0.3.0, < 3) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) + xpath (2.1.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + autoprefixer-rails + bootstrap-sass (~> 3.2.0) + byebug + capybara (~> 2.4.4) + coffee-rails (~> 4.1.0) + factory_girl_rails + faker + jbuilder (~> 2.0) + jquery-rails + pg (~> 0.18.4) + pry + rails (= 4.2.1) + rspec-rails (~> 3.6) + sass-rails (~> 5.0) + sdoc (~> 0.4.0) + shoulda (~> 3.5) + spring + sqlite3 (~> 1.3, >= 1.3.11) + turbolinks + uglifier (>= 1.3.0) + web-console (~> 2.0) + +BUNDLED WITH + 1.15.4 diff --git a/README.md b/README.md index 62fbac7..7a4bb1a 100644 --- a/README.md +++ b/README.md @@ -1,88 +1,53 @@ -# Techstars Engineering Fun with Code +## Company App ## -The Techstars Engineering team would like to congratulate you on making it to our coding challenge. This is your chance to show the team how you approach problems and give them insight into your ability to code. For the challenge, you will be required to design, develop, and style an MVC application. Feel free to use any third party libraries you see fit. Low-fi mockups have been provided, but please feel free to take your own artistic direction. You will have **one week** from the time you are granted access to this repository to submit a solution for the given requirements. Please read all the instructions carefully and email us if you have any questions. Good luck, but most of all have fun - this is your chance to demonstrate what you can do. +**A Companies Application built using Rails-4.2.1 with the following features:** -## Getting Started -First, fork this repository into your GitHub account. Then complete each of the parts below working as you would in a professional environment. Once you have completed all the sections, please update the README to reflect how to build and run your application, as well as any architectural decisions you have made. When you believe you are ready to submit your challenge, submit a pull request into our master branch. We will see the notification and get back to you on next steps. +* CRUD operations for Companies +* Ability to create and view the Founders associated with the Companies +* Ability to tag Companies with categories and view the tags. -## What we are looking for +### Getting Started -* Ability to set up an MVC applicatoin (Strongly Recommend Rails). -* Ability to set up a Relational Database -* Understanding of the HTTP protocol and how it works with Rails' "RESTful" conventions -* Understanding the basics of CRUD - * Create - * Read - * Update - * Delete -* Ability to layout and design an HTML page with CSS -* Ability to develop automated tests for your application -* Ability to interpret requirements +Fork, clone, and cd into the project directory +Install the dependencies -## The Challenge +`bundle install` -### Intro +Create Database -Build an application that will be a directory of companies, and the people who have founded them. The main page should be a list of all the companies with some high-level information (Name, Short Description, City, State). When the user click on a company, show its details. Included in those details will be the founding members of company, a long description, and a collection of categories the company belongs to. +`rake db:create` -### Part 1 : Companies Index +Run Migrations -1. Create the basic layout for the page -2. Create a list view of all companies - * Company Name - * Company Location - * Short Description -3. Add ability to create a new company -
+`rake db:migrate` -![step 1](Step_1.png) +Seed your database with fake companies and founders -### Part 2 : Companies Create +`rake db:seed` -1. Implement form to create a new company -2. Fields - * Company Name __required__ - * Company Location (City, State) __required__ - * Company Description __required__ - * Founded Date -
+Start up your server! -![step 2](Step_2.png) +`rails server` -### Part 3 : Company Details +To see a live version, visit: -1. Shows all of the company's information -2. Ability to update company -3. Ability to delete company -
+http://companiesandfounders.herokuapp.com/ -![step 3](Step_3.png) +### Testing -### Part 4 : Founders +**Controller and Model Tests** +located in the spec directory -1. In the Company details add the ability to add a Founder to a Company. -2. Each Founder can only belong to a single company. -3. Founder Fields - * Founder Full Name - * Founder Title -4. Founders added should display in the company detail page. -
+To run tests run +`$ rspec` -![step 4](Step_4.png) +### Database Relationships / Associations -### Part 5 : Tags - -1. In the Company details add the ability to tag a company with categories. -2. Each category can belong to a number of different companies. -3. Tags added should appear in the company detail page. -
- -![step 5](Step_5.png) - - -### Part 6 : Stretch Challenge -This section of the challange in not required but would give us greater insight into your abilities. - -1. Using the libraries and image hosting service of your choice, add the ability to upload images to a company. Then add the image into the index, show, and edit page. -2. Sign-up for a Heroku account and deploy your application to the web. Please provide us with deployed URL. +##### Companies +Companies have relationships with the following models in the database. +(*check schema.rb and the models to see associations.*) +* Founder +* Location +* Category +* Tagging diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..4996ac5 --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,18 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require bootstrap-sprockets +//= require_tree . + diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss new file mode 100644 index 0000000..70f82a2 --- /dev/null +++ b/app/assets/stylesheets/application.css.scss @@ -0,0 +1,34 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ +@import "bootstrap-sprockets"; +@import "bootstrap"; + +body { padding-top: 70px; } + +body { padding-bottom: 70px; } + +.panel { + padding-left: 30px; + padding-right: 30px; +} + +.top-space { + padding-top: 40px; +} + +.bottom-space { + padding-bottom: 40px; +} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb new file mode 100644 index 0000000..a09fe61 --- /dev/null +++ b/app/controllers/companies_controller.rb @@ -0,0 +1,51 @@ +class CompaniesController < ApplicationController + + def index + @companies = Company.all + end + + def new + @company = Company.new + @company.build_location + end + + def create + @company = Company.new(company_params) + if @company.save + redirect_to companies_path + else + render :new + end + end + + def edit + @company = Company.find(params[:id]) + end + + def update + @company = Company.find(params[:id]) + if @company.update(company_params) + redirect_to company_path(@company) + else + render :edit + end + end + + def show + @company = Company.find(params[:id]) + @taggings = @company.tag_list.split(',') + end + + def destroy + Company.destroy(params[:id]) + redirect_to companies_path + end + + private + + def company_params + params.require(:company).permit(:name, :description, :founded_date, :tag_list, + location_attributes: [:id, :city, :state, :_destroy]) + end + +end \ No newline at end of file diff --git a/app/controllers/founders_controller.rb b/app/controllers/founders_controller.rb new file mode 100644 index 0000000..84c61d5 --- /dev/null +++ b/app/controllers/founders_controller.rb @@ -0,0 +1,24 @@ +class FoundersController < ApplicationController + + before_action do + @company = Company.find(params[:company_id]) + end + + def new + @founder = Founder.new(:company_id => @company.id) + end + + def create + @founder = @company.founders.new(founder_params) + if @founder.save + redirect_to companies_path(@company.id) + end + end + + private + + def founder_params + params.require(:founder).permit(:full_name, :title, :company_id) + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/states_helper.rb b/app/helpers/states_helper.rb new file mode 100644 index 0000000..38f0a26 --- /dev/null +++ b/app/helpers/states_helper.rb @@ -0,0 +1,58 @@ +module StatesHelper + def us_states + [ + ['Alabama', 'AL'], + ['Alaska', 'AK'], + ['Arizona', 'AZ'], + ['Arkansas', 'AR'], + ['California', 'CA'], + ['Colorado', 'CO'], + ['Connecticut', 'CT'], + ['Delaware', 'DE'], + ['District of Columbia', 'DC'], + ['Florida', 'FL'], + ['Georgia', 'GA'], + ['Hawaii', 'HI'], + ['Idaho', 'ID'], + ['Illinois', 'IL'], + ['Indiana', 'IN'], + ['Iowa', 'IA'], + ['Kansas', 'KS'], + ['Kentucky', 'KY'], + ['Louisiana', 'LA'], + ['Maine', 'ME'], + ['Maryland', 'MD'], + ['Massachusetts', 'MA'], + ['Michigan', 'MI'], + ['Minnesota', 'MN'], + ['Mississippi', 'MS'], + ['Missouri', 'MO'], + ['Montana', 'MT'], + ['Nebraska', 'NE'], + ['Nevada', 'NV'], + ['New Hampshire', 'NH'], + ['New Jersey', 'NJ'], + ['New Mexico', 'NM'], + ['New York', 'NY'], + ['North Carolina', 'NC'], + ['North Dakota', 'ND'], + ['Ohio', 'OH'], + ['Oklahoma', 'OK'], + ['Oregon', 'OR'], + ['Pennsylvania', 'PA'], + ['Puerto Rico', 'PR'], + ['Rhode Island', 'RI'], + ['South Carolina', 'SC'], + ['South Dakota', 'SD'], + ['Tennessee', 'TN'], + ['Texas', 'TX'], + ['Utah', 'UT'], + ['Vermont', 'VT'], + ['Virginia', 'VA'], + ['Washington', 'WA'], + ['West Virginia', 'WV'], + ['Wisconsin', 'WI'], + ['Wyoming', 'WY'] + ] + end +end \ No newline at end of file diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..456111c --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,8 @@ +class Category < ActiveRecord::Base + has_many :taggings, dependent: :destroy + has_many :companies, through: :taggings + + def to_s + name + end +end \ No newline at end of file diff --git a/app/models/company.rb b/app/models/company.rb new file mode 100644 index 0000000..825e8c8 --- /dev/null +++ b/app/models/company.rb @@ -0,0 +1,25 @@ +class Company < ActiveRecord::Base + + has_many :founders, dependent: :destroy + has_one :location + has_many :taggings, dependent: :destroy + has_many :categories, through: :taggings + + accepts_nested_attributes_for :location + + validates :name, presence: true + validates :description, presence: true + validates :location, presence: true + + def tag_list + self.categories.collect do |category| + category.name + end.join(", ") + end + + def tag_list=(categories_string) + category_names = categories_string.split(",").collect{|s| s.strip.downcase}.uniq + new_or_found_tags = category_names.collect { |name| Category.find_or_create_by(name: name) } + self.categories = new_or_found_tags + end +end \ No newline at end of file diff --git a/app/models/founder.rb b/app/models/founder.rb new file mode 100644 index 0000000..e245186 --- /dev/null +++ b/app/models/founder.rb @@ -0,0 +1,3 @@ +class Founder < ActiveRecord::Base + belongs_to :company +end \ No newline at end of file diff --git a/app/models/location.rb b/app/models/location.rb new file mode 100644 index 0000000..d361a58 --- /dev/null +++ b/app/models/location.rb @@ -0,0 +1,6 @@ +class Location < ActiveRecord::Base + belongs_to :company + + validates :city, presence: true + validates :state, presence: true +end \ No newline at end of file diff --git a/app/models/tagging.rb b/app/models/tagging.rb new file mode 100644 index 0000000..909dc49 --- /dev/null +++ b/app/models/tagging.rb @@ -0,0 +1,4 @@ +class Tagging < ActiveRecord::Base + belongs_to :category + belongs_to :company +end \ No newline at end of file diff --git a/app/views/companies/_form.erb b/app/views/companies/_form.erb new file mode 100644 index 0000000..d1d6976 --- /dev/null +++ b/app/views/companies/_form.erb @@ -0,0 +1,69 @@ +
+
+ + <%= form_for @company, :html => { :class => "form-horizontal" } do |f| %> + + <% if @company.errors.any? %> +
+ +

<%= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:" %>

+
    + <% @company.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :name, :class => 'col-sm-2 control-label' %> +
+ <%= f.text_field :name, :class => 'form-control' %> +
+
+ + <%= f.fields_for :location, @company.location do |location_form| %> +
+ <%= location_form.label :city, :class => 'col-sm-2 control-label' %> +
+ <%= location_form.text_field :city, :class => 'form-control' %> +
+
+
+ <%= location_form.label :state, :class => 'col-sm-2 control-label' %> +
+ <%= location_form.select(:state, options_for_select(us_states, "CA"), {}, {class: 'form-control'}) %> +
+
+ <% end %> + +
+ <%= f.label :founded_date, :class => 'col-sm-2 control-label' %> +
+ <%= f.date_field :founded_date, :class => 'form-control' %> +
+
+ +
+ <%= f.label :tag_list, :class => 'col-sm-2 control-label' %> +
+ <%= f.text_field :tag_list, placeholder: "Tags separated with comma", :class => 'form-control' %> +
+
+ +
+ <%= f.label :description, :class => 'col-sm-2 control-label' %> +
+ <%= f.text_field :description, :class => 'form-control' %> +
+
+ +
+
+ <%= f.submit :class => 'btn btn-primary' %> +
+
+ + <% end %> +
+
\ No newline at end of file diff --git a/app/views/companies/edit.html.erb b/app/views/companies/edit.html.erb new file mode 100644 index 0000000..75bdf7e --- /dev/null +++ b/app/views/companies/edit.html.erb @@ -0,0 +1,11 @@ + + +
+

Edit Your Company Profile

+
+ +<%= render 'form' %> \ No newline at end of file diff --git a/app/views/companies/index.html.erb b/app/views/companies/index.html.erb new file mode 100644 index 0000000..1ec8614 --- /dev/null +++ b/app/views/companies/index.html.erb @@ -0,0 +1,21 @@ + + +<% @companies.each do |company| %> +
+
+
+

<%= "#{company.name}"+ " |" %>

+

+ <%= "#{company.location.city}, " "#{company.location.state }" %> +

+
+

<%= company.description.split[0..100].join(' ') %>

+
<%= link_to 'more', company_path(company.id), class: 'btn btn-info pull-right' %>
+
+
+<% end %> + +<%= link_to 'Add Company', new_company_path, class: 'btn btn-success pull-right' %> \ No newline at end of file diff --git a/app/views/companies/new.html.erb b/app/views/companies/new.html.erb new file mode 100644 index 0000000..9002de6 --- /dev/null +++ b/app/views/companies/new.html.erb @@ -0,0 +1,10 @@ + + +
+

Create Your Company Profile

+
+ +<%= render 'form' %> \ No newline at end of file diff --git a/app/views/companies/show.html.erb b/app/views/companies/show.html.erb new file mode 100644 index 0000000..3456194 --- /dev/null +++ b/app/views/companies/show.html.erb @@ -0,0 +1,51 @@ + + +
+ +
+
+ <%= link_to 'Edit', edit_company_path(@company), class: 'btn btn-primary float-right' %> + <%= link_to 'Delete', @company, method: :delete, confirm: "Are you sure?", class: 'btn btn-danger float-right' %> +
+
+ +
+
+

<%= @company.name %>

+
+
+

<%= "#{@company.founded_date.to_formatted_s(:long)} " "#{@company.location.city}, #{@company.location.state}" %>

+
+
+ +
+

<%= @company.description %>

+
+ +
+
+

Founders

+
+ <% @company.founders.each do |founder| %> +
<%= "#{founder.full_name} : ""#{founder.title}" %>
+ <% end %> +
+ <%= link_to 'Add Founder', new_company_founder_path(@company.id), class: 'btn btn-info pull-right' %> +
+
+ +
+
+

Categories

+
+ <% @taggings.each do |tag|%> + <%= tag %> + <%end %> +
+ <%= link_to 'Add Category Tag', edit_company_path(@company.id), class: 'btn btn-info pull-right' %> +
+
+ +
\ No newline at end of file diff --git a/app/views/founders/new.html.erb b/app/views/founders/new.html.erb new file mode 100644 index 0000000..7fe259a --- /dev/null +++ b/app/views/founders/new.html.erb @@ -0,0 +1,54 @@ + + +
+

Add A Founder To Your Company

+
+ +
+
+ + <%= form_for [@company, @founder], :html => { :class => "form-horizontal" } do |f| %> + + <% if @founder.errors.any? %> +
+ +

+ <%= "#{pluralize(@company.errors.count, "error")} prohibited this company from being saved:" %> +

+
    + <% @founder.errors.full_messages.each do |msg| %> +
  • + <%= msg %> +
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :full_name, :class => 'col-sm-2 control-label' %> +
+ <%= f.text_field :full_name, :class => 'form-control' %> +
+
+ +
+ <%= f.label :title, :class => 'col-sm-2 control-label' %> +
+ <%= f.text_field :title, :class => 'form-control' %> +
+
+ +
+
+ <%= f.submit :class => 'btn btn-primary' %> +
+
+ + <% end %> +
+
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..1fe1bea --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,18 @@ + + + + CodeChallenge + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + +
+
+
+ <%= yield %> +
+
+
+ + diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..0138d79 --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..d87d5f5 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..acdb2c1 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000..fb2ec2e --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..bd83b25 --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..fd53c73 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,10 @@ +require File.expand_path('../boot', __FILE__) +require 'rails/all' + +Bundler.require(*Rails.groups) + +module CodeChallenge + class Application < Rails::Application + config.active_record.raise_in_transactional_callbacks = true + end +end \ No newline at end of file diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..6b750f0 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..15b4f51 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,26 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: postgresql + pool: 5 + timeout: 5000 + +development: + <<: *default + database: my_database_development + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: my_database_development + + +production: + <<: *default + database: my_database_development \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..ee8d90d --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..83d6b72 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + config.action_controller.include_all_helpers = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..8366dbf --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,80 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + config.action_controller.include_all_helpers = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..1c19f08 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Randomize the order test cases are executed. + config.active_support.test_order = :random + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..01ef3e6 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..7f70458 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..8f80046 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_codeChallenge_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..0312971 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,8 @@ +Rails.application.routes.draw do + + root 'companies#index' + + resources :companies do + resources :founders, only: [:new, :create] + end +end \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..f30005a --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: ad90a5ac0e6994a2a39cf9f94979dcba6b77c1692df5e82a1f7fd4dd84110f7e27c648ff9350cd93b035fe2b5b01dbb990638b2765df42efba7dbd110aac0644 + +test: + secret_key_base: 8eff9424aef2a9dc86e793b9d984bcf6e7e4066f546e686004cc658a2c20d9b8749fe7f9c483cffc6b23c705c162deffa9b47d15abddd0a614799e78584c6e8c + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/db/migrate/20171007154708_create_companies.rb b/db/migrate/20171007154708_create_companies.rb new file mode 100644 index 0000000..3e96cc6 --- /dev/null +++ b/db/migrate/20171007154708_create_companies.rb @@ -0,0 +1,11 @@ +class CreateCompanies < ActiveRecord::Migration + def change + create_table :companies do |t| + t.string :name + t.text :description + t.date :founded_date + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20171007192636_create_founders.rb b/db/migrate/20171007192636_create_founders.rb new file mode 100644 index 0000000..279a6d0 --- /dev/null +++ b/db/migrate/20171007192636_create_founders.rb @@ -0,0 +1,11 @@ +class CreateFounders < ActiveRecord::Migration + def change + create_table :founders do |t| + t.string :full_name + t.string :title + t.belongs_to :company + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20171007193326_create_locations.rb b/db/migrate/20171007193326_create_locations.rb new file mode 100644 index 0000000..e312a34 --- /dev/null +++ b/db/migrate/20171007193326_create_locations.rb @@ -0,0 +1,11 @@ +class CreateLocations < ActiveRecord::Migration + def change + create_table :locations do |t| + t.string :city + t.string :state + t.belongs_to :company + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20171008031844_create_categories.rb b/db/migrate/20171008031844_create_categories.rb new file mode 100644 index 0000000..b574669 --- /dev/null +++ b/db/migrate/20171008031844_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration + def change + create_table :categories do |t| + t.string :name + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20171008032444_create_taggings.rb b/db/migrate/20171008032444_create_taggings.rb new file mode 100644 index 0000000..62a0430 --- /dev/null +++ b/db/migrate/20171008032444_create_taggings.rb @@ -0,0 +1,10 @@ +class CreateTaggings < ActiveRecord::Migration + def change + create_table :taggings do |t| + t.references :category, index: true, foreign_key: true + t.references :company, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..29c1601 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,61 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20171008032444) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "companies", force: :cascade do |t| + t.string "name" + t.text "description" + t.date "founded_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "founders", force: :cascade do |t| + t.string "full_name" + t.string "title" + t.integer "company_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "locations", force: :cascade do |t| + t.string "city" + t.string "state" + t.integer "company_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "taggings", force: :cascade do |t| + t.integer "category_id" + t.integer "company_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "taggings", ["category_id"], name: "index_taggings_on_category_id", using: :btree + add_index "taggings", ["company_id"], name: "index_taggings_on_company_id", using: :btree + + add_foreign_key "taggings", "categories" + add_foreign_key "taggings", "companies" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..3ae79fc --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,26 @@ +Company.destroy_all + +10.times do + company = Company.new( + name: Faker::Company.name, + description: Faker::Lorem.paragraph(40), + founded_date: Faker::Time.between(2.days.ago, Date.today, :all) + ) + company.location = Location.new( + state: Faker::Address.state, + city: Faker::Address.city + ) + company.founders << Founder.new( + full_name: Faker::Name.name, + title: Faker::Name.title + ) + category1 = Category.new( name: "IoT") + category2 = Category.new(name: "Ruby") + founder1 = Founder.new(full_name: "Jane Doe", title: "CEO") + + company.taggings << Tagging.new(category: category1) + company.founders << founder1 + company.save +end + +p "Created #{Company.count} companies" \ No newline at end of file diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..3c9c7c0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/spec/controllers/companies_controller_spec.rb b/spec/controllers/companies_controller_spec.rb new file mode 100644 index 0000000..f9c659d --- /dev/null +++ b/spec/controllers/companies_controller_spec.rb @@ -0,0 +1,105 @@ +require "rails_helper" + +describe CompaniesController do + + before do + Company.destroy_all + Location.destroy_all + end + + describe "GET #index" do + it "Should render the Company Index View" do + + location1 = Location.create(city: "SF", state: "CA", company_id: 1) + location2 = Location.create(city: "Pacifica", state: "CA", company_id: 2) + + company1 = Company.create(name: "Audrey's Farm", description: "A farm full of horses.", location: location1, id: 1) + company2 = Company.create(name: "Zoey's Zoo", description: "A zoo full of animals.", location: location2, id: 2) + + get :index + + expect(response).to render_template(:index) + expect(response.status).to eq(200) + expect(assigns(:companies)).to eq [company1, company2] + end + end + + describe "GET #show" do + it "shows an individual company" do + + location1 = Location.create(city: "SF", state: "CA", company_id: 1) + company1 = Company.create(name: "Audrey's Farm", description: "A farm full of horses", id: 1) + + get :show, id: 1 + + expect(response.status).to eq(200) + expect(response).to render_template :show + expect(assigns(:company)).to eq company1 + end + end + + describe "GET #new" do + it "renders new form" do + + get :new + + expect(response.status).to eq(200) + expect(response).to render_template :new + expect(assigns(:company)).to be_a_new(Company) + end + end + + describe "POST #create" do + it "creates new company" do + + expect { + post :create, + company: {name: "emmy dogpark inc", description: "a dogpark for all dogs", location_attributes: {city: "Pacifica", state: "CO"}} + }.to change {Company.all.count}.by(1) + expect(response.status).to eq(302) + end + end + + describe "GET #edit" do + it "allows edit of a company" do + + location = Location.create(city: "Pacifica", state: "CA", company_id: 2) + company = Company.create(id: 2, name: "starfleet.io", description: "We love Star Trek here.") + + get :edit, id: 2 + + expect(response).to render_template :edit + expect(response.status).to eq(200) + expect(assigns(:company)).to eq company + end + end + + describe "PATCH update" do + it "updates a company" do + + location = Location.create(city: "Pacifica", state: "CA", company_id: 2) + company = Company.create(id: 2, name: "starfleet.io", description: "We love Star Trek here.") + + patch :update, id: 2, company: {name: "starfleet.io", description: "This description is updated."} + + expect(response.status).to eq(302) + expect(response).to redirect_to company_path(2) + expect(Company.find(2).description).to eq("This description is updated.") + end + end + + describe "DESTROY" do + it "allows for deletion of a company" do + + location = Location.create(city: "Pacifica", state: "CA", company_id: 2) + company = Company.create(name: "starfleet.io", description: "We love Star Trek here.", id: 2) + + delete :destroy, id: company.id + + expect(response.status).to eq(302) + expect(response).to redirect_to companies_path + expect(Company.all.count).to eq(0) + end + end + +end \ No newline at end of file diff --git a/spec/factories/categories.rb b/spec/factories/categories.rb new file mode 100644 index 0000000..2367ef5 --- /dev/null +++ b/spec/factories/categories.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :category do + name "MyString" + end +end diff --git a/spec/factories/company.rb b/spec/factories/company.rb new file mode 100644 index 0000000..6e83fa0 --- /dev/null +++ b/spec/factories/company.rb @@ -0,0 +1,9 @@ +require 'faker' + +FactoryGirl.define do + factory :company do + name Faker::Company.name + description Faker::Lorem.paragraph(2) + founded_date Faker::Date + end +end \ No newline at end of file diff --git a/spec/factories/founders.rb b/spec/factories/founders.rb new file mode 100644 index 0000000..3c61722 --- /dev/null +++ b/spec/factories/founders.rb @@ -0,0 +1,8 @@ +require 'faker' + +FactoryGirl.define do + factory :founder do + full_name Faker::Name.name + title Faker::Name.title + end +end \ No newline at end of file diff --git a/spec/factories/locations.rb b/spec/factories/locations.rb new file mode 100644 index 0000000..6d8e8bf --- /dev/null +++ b/spec/factories/locations.rb @@ -0,0 +1,8 @@ +require 'faker' + +FactoryGirl.define do + factory :location do + city Faker::Address.city + state Faker::Address.state + end +end diff --git a/spec/factories/taggings.rb b/spec/factories/taggings.rb new file mode 100644 index 0000000..1ed7a40 --- /dev/null +++ b/spec/factories/taggings.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :tagging do + category nil + company nil + end +end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb new file mode 100644 index 0000000..724aec1 --- /dev/null +++ b/spec/models/category_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe Category, type: :model do + it { should have_many(:companies).through(:taggings)} + it { should have_many(:taggings) } + +end diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb new file mode 100644 index 0000000..aefe499 --- /dev/null +++ b/spec/models/company_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe Company, type: :model do + + describe 'validations' do + it { should validate_presence_of(:name) } + it { should validate_presence_of(:description) } + it { should validate_presence_of(:location) } + end + + describe 'associations' do + it { should have_many(:founders) } + it { should have_one(:location) } + it { should have_many(:taggings) } + it { should have_many(:categories).through(:taggings) } + + end + +end \ No newline at end of file diff --git a/spec/models/founder_spec.rb b/spec/models/founder_spec.rb new file mode 100644 index 0000000..2ef62cb --- /dev/null +++ b/spec/models/founder_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe Founder, type: :model do + describe 'associations' do + it { should belong_to(:company) } + end +end \ No newline at end of file diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb new file mode 100644 index 0000000..563458d --- /dev/null +++ b/spec/models/location_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe Location, type: :model do + + describe 'validations' do + it { should validate_presence_of(:city) } + it { should validate_presence_of(:state) } + it { should belong_to(:company) } + end + + describe 'associations' do + it { should belong_to(:company) } + end +end diff --git a/spec/models/tagging_spec.rb b/spec/models/tagging_spec.rb new file mode 100644 index 0000000..1892dfe --- /dev/null +++ b/spec/models/tagging_spec.rb @@ -0,0 +1,8 @@ +require 'rails_helper' + +RSpec.describe Tagging, type: :model do + describe 'associations' do + it { should belong_to(:company) } + it { should belong_to(:category) } + end +end \ No newline at end of file diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..cdf23f9 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,17 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' + +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.include FactoryGirl::Syntax::Methods + config.use_transactional_fixtures = true + config.infer_spec_type_from_file_location! + config.filter_rails_from_backtrace! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..7af1557 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + config.shared_context_metadata_behavior = :apply_to_host_groups +end \ No newline at end of file diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29