diff --git a/.DS_Store b/.DS_Store index 861ce21..797e7a7 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Gemfile b/Gemfile index b7d7aab..93debf9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,17 @@ source 'https://rubygems.org' +group :development, :test do + gem 'sqlite3' +end +group :production do + gem 'pg', '~> 0.18' +end +#gem 'jquery-rails' + # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '5.0.2' # Use sqlite3 as the database for Active Record -gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -42,6 +49,7 @@ gem 'draper' gem 'pundit' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -54,6 +62,10 @@ gem 'pundit' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + #Use RSpec-rails for testing + gem 'rspec-rails', '~> 3.8' + gem 'capybara' + end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 1ef8616..9dbcc97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,16 +24,16 @@ GEM erubis (~> 2.7.0) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activeadmin (1.1.0) + activeadmin (1.4.1) arbre (>= 1.1.1) coffee-rails formtastic (~> 3.1) formtastic_i18n - inherited_resources (~> 1.7) - jquery-rails - kaminari (>= 0.15, < 2.0) - railties (>= 4.2, < 5.2) - ransack (~> 1.3) + inherited_resources (>= 1.9.0) + jquery-rails (>= 4.2.0) + kaminari (>= 0.15) + railties (>= 4.2, < 5.3) + ransack (>= 1.8.7) sass (~> 3.1) sprockets (< 4.1) activejob (5.0.2) @@ -54,15 +54,26 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) arbre (1.1.1) activesupport (>= 3.0.0) arel (7.1.4) - bcrypt (3.1.11) - binding_of_caller (0.7.2) + bcrypt (3.1.12) + bcrypt (3.1.12-x86-mingw32) + binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) builder (3.2.3) - byebug (9.1.0) + byebug (10.0.2) cancan (1.6.10) + capybara (3.11.1) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.2) + xpath (~> 3.2) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -70,15 +81,16 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.2) + concurrent-ruby (1.1.3) + crass (1.0.4) debug_inspector (0.0.3) - devise (4.3.0) + devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.2) + railties (>= 4.1.0, < 6.0) responders warden (~> 1.2.3) + diff-lcs (1.3) draper (3.0.1) actionpack (~> 5.0) activemodel (~> 5.0) @@ -87,7 +99,8 @@ GEM request_store (~> 1.0) erubis (2.7.0) execjs (2.7.0) - ffi (1.9.18) + ffi (1.9.25) + ffi (1.9.25-x86-mingw32) formtastic (3.1.5) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) @@ -96,20 +109,20 @@ GEM haml (5.0.4) temple (>= 0.8.0) tilt - has_scope (0.7.1) - actionpack (>= 4.1, < 5.2) - activesupport (>= 4.1, < 5.2) - i18n (0.9.1) + has_scope (0.7.2) + actionpack (>= 4.1) + activesupport (>= 4.1) + i18n (0.9.5) concurrent-ruby (~> 1.0) - inherited_resources (1.7.2) - actionpack (>= 3.2, < 5.2.x) + inherited_resources (1.9.0) + actionpack (>= 4.2, < 5.3) has_scope (~> 0.6) - railties (>= 3.2, < 5.2.x) + railties (>= 4.2, < 5.3) responders - jbuilder (2.7.0) + jbuilder (2.8.0) activesupport (>= 4.2.0) multi_json (>= 1.2) - jquery-rails (4.3.1) + jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -126,25 +139,28 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - loofah (2.1.1) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) - method_source (0.9.0) - mini_mime (0.1.4) + method_source (0.9.2) + mini_mime (1.0.1) mini_portile2 (2.3.0) - minitest (5.10.3) - multi_json (1.12.1) - nio4r (2.1.0) - nokogiri (1.8.1) + minitest (5.11.3) + multi_json (1.13.1) + nio4r (2.3.1) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + nokogiri (1.8.5-x86-mingw32) mini_portile2 (~> 2.3.0) orm_adapter (0.5.0) - polyamorous (1.3.1) - activerecord (>= 3.0) - pundit (1.1.0) + pg (0.21.0) + pg (0.21.0-x86-mingw32) + public_suffix (3.0.3) + pundit (2.0.0) activesupport (>= 3.0.0) - rack (2.0.3) + rack (2.0.6) rack-cors (0.3.1) rack-test (0.6.3) rack (>= 1.0) @@ -163,35 +179,53 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) railties (5.0.2) actionpack (= 5.0.2) activesupport (= 5.0.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.2.1) - ransack (1.8.4) - actionpack (>= 3.0) - activerecord (>= 3.0) - activesupport (>= 3.0) + rake (12.3.1) + ransack (2.1.0) + actionpack (>= 5.0) + activerecord (>= 5.0) + activesupport (>= 5.0) i18n - polyamorous (~> 1.3) - rb-fsevent (0.10.2) + rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) rdoc (4.3.0) - request_store (1.3.2) + regexp_parser (1.3.0) + request_store (1.4.1) + rack (>= 1.4) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) - sass (3.5.1) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-rails (3.8.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + sass (3.7.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) + sass-rails (5.0.7) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) @@ -200,12 +234,12 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - simple_form (3.5.0) - actionpack (> 4, < 5.2) - activemodel (> 4, < 5.2) + simple_form (4.1.0) + actionpack (>= 5.0) + activemodel (>= 5.0) spring (2.0.2) activesupport (>= 4.2) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) @@ -213,19 +247,20 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) + sqlite3 (1.3.13-x86-mingw32) temple (0.8.0) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) tilt (2.0.8) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.3) - tzinfo (1.2.4) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (3.2.0) + uglifier (4.1.20) execjs (>= 0.3.0, < 3) - warden (1.2.7) - rack (>= 1.0) + warden (1.2.8) + rack (>= 2.0.6) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) @@ -233,24 +268,30 @@ GEM sprockets-rails (>= 2.0, < 4.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.3) + xpath (3.2.0) + nokogiri (~> 1.8) PLATFORMS ruby + x86-mingw32 DEPENDENCIES activeadmin byebug cancan + capybara coffee-rails (~> 4.1.0) devise draper haml jbuilder (~> 2.0) jquery-rails + pg (~> 0.18) pundit rack-cors (~> 0.3.1) rails (= 5.0.2) + rspec-rails (~> 3.8) sass-rails (~> 5.0) sdoc (~> 0.4.0) simple_form @@ -261,4 +302,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.16.0 + 1.16.1 diff --git a/Instructions and Resources for the Next Team.docx b/Instructions and Resources for the Next Team.docx new file mode 100644 index 0000000..0b36bb5 Binary files /dev/null and b/Instructions and Resources for the Next Team.docx differ diff --git a/README.md b/README.md index 792b0dd..fb1812d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,88 @@ # LFC_Features +### Local Food Connection Application +LFC is a Grinnell farm directory service. It contains basic information of farms that are connected to Local Food Connection Organization. The goal of the app is to allow user to easily search for Grinnell's sustainable food system. + +You can obtain the source with the following command: +```shell +git clone https://github.com/CSC322-Grinnell/LFC_Features.git +``` + +## Authors and Contributors + +### Current Builds + +- [Joshua Cussen](https://github.com/nomadicTree) +- [Siyu Zhang](https://github.com/zhangsiyu1103) +- [Nolan Schoenle](https://github.com/NSchoenle) +- [Hoang Cao]() +- [Ryan Rosol]() + + +### Previous Builds + +- [Linh Pham](https://github.com/linhpha) +- [Pratik Karki](https://github.com/karkipra) +- [Elise Brod](https://github.com/brodelis) +- [James Msekela]() +- [Sara Marku](https://github.com/saramarku) + +### Project Structure + +The view for the main page is in /app/views/ui/view2.html.erb. +The CSS and JavaScript files are in /app/assets/javascripts/ and /app/assets/stylesheets/ respectively. +All images and icons are stored in /app/assets/images. +The admin page is contained in /app/admin folder. +/app/admin/farm.rb generates the UI of the Edit farm from admin page. + +### How to build + +The project can be installed on Cloud 9. +The Heroku website for the previous group's work on the project is http://localfoodsconnection.herokuapp.com +We do not have access to this Heroku. +You need to make a new Heroku to deploy the site. + +Next, to set up the database, run the commands: + +``` +bundle install +rake db:create +rake db:migrate +rake db:seed +rake db:seed:seed_farm +rake db:seed:seed_growing_method +rake db:seed:seed_selling_method +rake db:seed:seed_operation +rake db:seed:seed_market +``` + +After successfully seeding the database, you can start the app and get to the main page. +Note: In order to check if the the seeding of farms was successful in the Rails console type: Farm.count and the result should yield 7. The information for all farms will be in the admin page. You can go to this page by clicking the Sign In link of the main website and the credentials of the admin are: +``` +Email: admin@example.com +Password: password +``` +After successfully signing in to the admin page you can navigate to look and edit the farms currently in the database. You can add Operations, Selling Methods, Primary Operation and Growing Methods for each farm and the map on the main page will update accordingly. + +To Sign In as a registered farm, you can find the credentials of the registered farms in the /db/seed/seed_farm. + + +### Current state, future tasks, and tips +Please see `Instructions and Resources for the Next Team.docx`, also located in the Microsoft Teams Team for this project. + + +## License +``` +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +``` diff --git a/app/admin/farm.rb b/app/admin/farm.rb deleted file mode 100644 index d7dfc50..0000000 --- a/app/admin/farm.rb +++ /dev/null @@ -1,101 +0,0 @@ -ActiveAdmin.register Farm do - # See permitted parameters documentation: - # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters - # - # permit_params :list, :of, :attributes, :on, :model - # - # or - # - # permit_params do - # permitted = [:permitted, :attributes] - # permitted << :other if params[:action] == 'create' && current_user.admin? - # permitted - # end - - controller do - before_filter :authorize_index, only: :index - def authorize_index - # FarmPolicy::Scope.new(current_farm, Farm).resolve - Farm - end - - # before_filter :authorize_show_edit_destroy, only: [:show, :edit, :destroy] - # def authorize_show_edit_destroy - # authorize resource - # end - end - - # scope_to :current_farm, unless: proc{ :current_farm } - - permit_params do - permitted = [:name, :address, :phone, :email, :url, :facebook, :instagram, - :password, :password_confirmation, :twitter] - permitted << :approved if current_farm.admin? - permitted - end - - index do - selectable_column - id_column - column :name - column :email - column :role - column :created_at - - if current_farm.admin? - column :approved - end - - actions - end - - filter :name - filter :email - - form do |f| - f.inputs "Farm Details" do - f.input :name - f.input :contact_name - f.input :year - f.input :address - f.input :phone - f.input :email - f.input :url - f.input :statement - - - f.input :facebook - f.input :instagram - f.input :twitter - f.input :other_media - - @ops = ['Fruit', 'Vegetables', 'Dairy', 'Pork', 'Chicken', 'Turkey', 'Lamb', 'Duck', 'Agitourism', 'Hay', 'Row Crop'] - @grow = ['Certified Natural Grown', 'USDA Certified Organic', '100% Grass Fed', 'Grass Finished', 'Non-GMO', 'Regenerative Organic Certified', 'Integrated Pest Management', 'Pasture Raised', 'Corn Fed', 'Conventional'] - @sell = ['CSA', 'Farmers Market', 'Wholesale', 'Grocery Stores', 'Grinnell Area Local Food Source', 'On-Farm', 'Iowa Food Coop', 'Institutions', 'Restaurants'] - @market = ['Grinnell-Thursday', 'Grinnell-Saturday', "Des Moines Downtown-Saturday", "Cedar Rapids Downtown-Select Saturdays", "Iowa City-Saturday", "Tama-Toledo", "Brooklyn"] - f.input :operations, as: :check_boxes, collection: @ops - f.input :growing_methods, as: :check_boxes, collection: @grow - f.input :link_to_cert - f.input :selling_methods, as: :check_boxes, collection: @sell - f.input :markets, as: :check_boxes, collection: @market - - f.input :growth_promoter, as: :boolean, checked_value: true, unchecked_value: false - f.input :antibiotic, as: :boolean, checked_value: true, unchecked_value: false - - f.input :fav_activity - f.input :why_farm - - - #unless current_farm.admin? - f.input :password - f.input :password_confirmation - #end - - if current_farm.admin? - f.input :approved - end - - end - f.actions - end -end diff --git a/app/admin/farm_admin.rb b/app/admin/farm_admin.rb new file mode 100644 index 0000000..afcfbcb --- /dev/null +++ b/app/admin/farm_admin.rb @@ -0,0 +1,86 @@ +ActiveAdmin.register Farm do + controller do + # before_filter :authorize_index, only: :index #Deprecated in Rails 5.1 + before_action :authorize_index, only: :index # + def authorize_index + # FarmPolicy::Scope.new(current_farm, Farm).resolve + Farm + end + + # before_filter :authorize_show_edit_destroy, only: [:show, :edit, :destroy] + # def authorize_show_edit_destroy + # authorize resource + # end + end + + # scope_to :current_farm, unless: proc{ :current_farm } + ## Add strong parameters for admin to be able to edit these fields + permit_params :name, :address, :phone, :email, :url, :facebook, :instagram, :password, + :password_confirmation, :primary_operation_id, :growth_promoter, :antibiotic, :why_farm, + :fav_activity, :twitter, :approved, operation_ids: [], selling_method_ids: [], + growing_method_ids: [], market_ids: [] + ##Doe not making sense +###### AAAAAAAAAAAAAAAAAA + index do + selectable_column + id_column + column :name + column :email + column :role + column :created_at + + if current_farm.admin? + column :approved + end + + actions + end + + filter :name + filter :email + + form do |f| + f.inputs "Farm Details" do + f.input :name + f.input :contact_name #Not sure if we ever do anything with this + f.input :year + f.input :address + f.input :phone + f.input :email + f.input :url + f.input :statement + + + f.input :facebook + f.input :instagram + f.input :twitter + f.input :other_media + + + f.input :operations, as: :check_boxes, collection: Operation.all + f.input :primary_operation, as: :select, collection: Operation.all + f.input :growing_methods, as: :check_boxes, collection: GrowingMethod.all + f.input :link_to_cert + f.input :selling_methods, as: :check_boxes, collection: SellingMethod.all + f.input :markets, as: :check_boxes, collection: Market.all + + f.input :growth_promoter, as: :boolean, checked_value: true, unchecked_value: false + f.input :antibiotic, as: :boolean, checked_value: true, unchecked_value: false + + f.input :fav_activity + f.input :why_farm + + + #unless current_farm.admin? + f.input :password + f.input :password_confirmation + #end + + if current_farm.admin? + f.input :approved + end + + end + f.actions + end +end diff --git a/javascript_app/icons/24apple.png b/app/assets/icons/24apple.png similarity index 100% rename from javascript_app/icons/24apple.png rename to app/assets/icons/24apple.png diff --git a/javascript_app/icons/24broccoli.png b/app/assets/icons/24broccoli.png similarity index 100% rename from javascript_app/icons/24broccoli.png rename to app/assets/icons/24broccoli.png diff --git a/javascript_app/icons/24chicken.png b/app/assets/icons/24chicken.png similarity index 100% rename from javascript_app/icons/24chicken.png rename to app/assets/icons/24chicken.png diff --git a/javascript_app/icons/24cow.png b/app/assets/icons/24cow.png similarity index 100% rename from javascript_app/icons/24cow.png rename to app/assets/icons/24cow.png diff --git a/javascript_app/icons/24dairy.png b/app/assets/icons/24dairy.png similarity index 100% rename from javascript_app/icons/24dairy.png rename to app/assets/icons/24dairy.png diff --git a/javascript_app/icons/24pig.png b/app/assets/icons/24pig.png similarity index 100% rename from javascript_app/icons/24pig.png rename to app/assets/icons/24pig.png diff --git a/javascript_app/icons/24sheep.png b/app/assets/icons/24sheep.png similarity index 100% rename from javascript_app/icons/24sheep.png rename to app/assets/icons/24sheep.png diff --git a/javascript_app/icons/64cow.png b/app/assets/icons/64cow.png similarity index 100% rename from javascript_app/icons/64cow.png rename to app/assets/icons/64cow.png diff --git a/app/assets/icons/agricultural.png b/app/assets/icons/agricultural.png new file mode 100644 index 0000000..a151cff Binary files /dev/null and b/app/assets/icons/agricultural.png differ diff --git a/app/assets/icons/carrot.png b/app/assets/icons/carrot.png new file mode 100644 index 0000000..6b1b1d2 Binary files /dev/null and b/app/assets/icons/carrot.png differ diff --git a/app/assets/icons/dairy_free.png b/app/assets/icons/dairy_free.png new file mode 100644 index 0000000..43c9bde Binary files /dev/null and b/app/assets/icons/dairy_free.png differ diff --git a/app/assets/icons/egg.png b/app/assets/icons/egg.png new file mode 100644 index 0000000..df644d8 Binary files /dev/null and b/app/assets/icons/egg.png differ diff --git a/app/assets/icons/gluten_free.png b/app/assets/icons/gluten_free.png new file mode 100644 index 0000000..558d955 Binary files /dev/null and b/app/assets/icons/gluten_free.png differ diff --git a/app/assets/icons/kosher.png b/app/assets/icons/kosher.png new file mode 100644 index 0000000..30b07b7 Binary files /dev/null and b/app/assets/icons/kosher.png differ diff --git a/app/assets/icons/peanut_free.jpg b/app/assets/icons/peanut_free.jpg new file mode 100644 index 0000000..ca38b82 Binary files /dev/null and b/app/assets/icons/peanut_free.jpg differ diff --git a/app/assets/icons/steak-512.png b/app/assets/icons/steak-512.png new file mode 100644 index 0000000..c5182d0 Binary files /dev/null and b/app/assets/icons/steak-512.png differ diff --git a/app/assets/icons/tree_nut_free.jpg b/app/assets/icons/tree_nut_free.jpg new file mode 100644 index 0000000..5eda7af Binary files /dev/null and b/app/assets/icons/tree_nut_free.jpg differ diff --git a/app/assets/icons/vegetarian.jpg b/app/assets/icons/vegetarian.jpg new file mode 100644 index 0000000..e78c81c Binary files /dev/null and b/app/assets/icons/vegetarian.jpg differ diff --git a/app/assets/images/favicon.png b/app/assets/images/favicon.png new file mode 100644 index 0000000..6b1b1d2 Binary files /dev/null and b/app/assets/images/favicon.png differ diff --git a/app/assets/images/hero.jpg b/app/assets/images/hero.jpg new file mode 100644 index 0000000..144d061 Binary files /dev/null and b/app/assets/images/hero.jpg differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png new file mode 100644 index 0000000..640bc00 Binary files /dev/null and b/app/assets/images/logo.png differ diff --git a/app/assets/javascripts/active_admin.js.coffee b/app/assets/javascripts/active_admin.js.coffee new file mode 100644 index 0000000..3752dce --- /dev/null +++ b/app/assets/javascripts/active_admin.js.coffee @@ -0,0 +1 @@ +#= require active_admin/base diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a8..f9302db 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,16 +1,35 @@ -// 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. -// +// To enable jquery for rails //= require jquery //= require jquery_ujs -//= require turbolinks //= require_tree . +var map; +var geocoder; + +/*********** + * API_KEYS * + ***********/ +var edemam_app_id = "0649d198"; +var edemam_app_key = "77bd12dd099e7f2c02338006ef659724"; +var lfc_key = "YAS0sY2rbi"; + +/******** + * INIT * + ********/ + $(window).on('load',function() { + if(window.location.pathname == '/') { + set_up_search(); + initialize_farms(); + } +}); + +/** + Set up farm cards + **/ +function initialize_farms() { + var call_url = "/farms/farm_json"; + callIndexApi(call_url, Visualize_Farm) +} + + + + diff --git a/app/assets/javascripts/farm_api.js b/app/assets/javascripts/farm_api.js new file mode 100644 index 0000000..0701543 --- /dev/null +++ b/app/assets/javascripts/farm_api.js @@ -0,0 +1,33 @@ +/**************************************** + * API CALLS functions + * **************************************/ +/** + make a api call + @param + call_url: the url to retrieve messages from + callback: a callback function for the returned message + params: other parameters may be included in the callback functions + **/ +function callIndexApi(call_url, callback,params) { + $.ajax({ + type: "GET", + url: call_url, + headers: { + 'X-Auth-Token': lfc_key + }, + dataType: 'json', + contentType: 'application/json', + crossDomain: true, + async: false, + success: function(result) { + if (result != null || result.length > 0) { + callback(result,params); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + console.log("Status: " + textStatus); + console.log("Error: " + errorThrown); + } + }); + +} \ No newline at end of file diff --git a/app/assets/javascripts/map.js b/app/assets/javascripts/map.js new file mode 100644 index 0000000..6dd2606 --- /dev/null +++ b/app/assets/javascripts/map.js @@ -0,0 +1,98 @@ +/**************************************** + * GEOCODING AND ADDING MARKERS FUNCTIONS + * **************************************/ +/** + positioning farm and add markers + @param + farm: a json object of farm + **/ +function geocodeAddressAndAddMarker(farm) { + var address = farm.address; + geocoder.geocode({ + 'address': address + }, function(results, status) { + // if OK/200 status, add marker to map, else throw alert. + if (status === 'OK') { + addMarker(farm, results); + } else { + alert('Geocode was not successful for the following reason: ' + status); + } + }); +} + +var markers = [] +/** + add markers to the map + @param + farm: a json object of farm + results: the return value of geocode function + **/ + function addMarker(farm, results) { + var marker = new google.maps.Marker({ + map: map, + position: results[0].geometry.location, + title: farm.name, + }); + + // data string for display tooltip + var data = farm.name; + // info window for tooltip, contains data + var infowindow = new google.maps.InfoWindow({ + content: data + }); + // add listener to map for marker to display info window + google.maps.event.addListener(marker, 'click', function() { + // open info window + infowindow.open(map, marker); + }); + markers.push(marker); +} +/** + show markers on the map + @param + results: an array of farm jsons + **/ +function showMarkers(result){ + for (var i = 0; i < result.length; i++) { + // add marker at proper place + geocodeAddressAndAddMarker(result[i]); + } +} + + +/*********************** + * DELETE MARKERS ON MAP * + * *********************/ + +function DeleteMarkers() { + //Loop through all the markers and remove + for (var i = 0; i < markers.length; i++) { + markers[i].setMap(null); + } + markers = []; +}; +/************* + * INIT MAP * + * ***********/ +function initMap() { + // set location set to grinnell as center of map + var grinnell = { + lat: 41.7434, + lng: -92.7232 + }; + + // init map + map = new google.maps.Map(document.getElementById('farmmap'), { + zoom: 12, + center: grinnell + }); + + // init geocoder + geocoder = new google.maps.Geocoder(); + + + //make a ajax call to show all the markers + var call_url = "/farms/farm_json"; + callIndexApi(call_url, showMarkers) + +} \ No newline at end of file diff --git a/app/assets/javascripts/model_method.js b/app/assets/javascripts/model_method.js new file mode 100644 index 0000000..52e86b4 --- /dev/null +++ b/app/assets/javascripts/model_method.js @@ -0,0 +1,194 @@ +//Used for modal, disgarded right now, may be used later + +/******************** + * MODAL FUNCTIONS * + * ******************/ +function capitalize_words(str) { + return str.replace(/\w\S*/g, function(txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); +} + +function getOperation(farm) { + var result = ""; + if (!farm.operations) { + farm = farm[0]; + } + for (var i = 0; i < farm.operations.length; i++) { + result += capitalize_words(farm.operations[i].food); + if (i != farm.operations.length - 1) { + result += ', '; + } + } + + if (result == "") { + return "N/A" + } + return result; +} + +function getGrowingMethod(farm) { + var result = ""; + if (!farm.growing_methods) { + farm = farm[0]; + } + for (var i = 0; i < farm.growing_methods.length; i++) { + result += capitalize_words(farm.growing_methods[i].grow_method); + if (i != farm.growing_methods.length - 1) { + result += ', '; + } + } + if (result == "") { + return "N/A" + } + return result +} + +function getSellingMethod(farm) { + var result = ""; + if (!farm.selling_methods) { + farm = farm[0]; + } + for (var i = 0; i < farm.selling_methods.length; i++) { + result += capitalize_words(farm.selling_methods[i].sell_method); + if (i != farm.selling_methods.length - 1) { + result += ', '; + } + } + + if (result == "") { + return "N/A" + } + return result; +} + +function setAndShowFarmModal(farm) { + if (!farm.operations) { + farm = farm[0]; + } + var primary_operation; + var farm_operations = farm.operations; + var primary_operation_id = farm.primary_operation_id; + for (var operation of farm_operations) { + if (operation.id == primary_operation_id) { + primary_operation = operation.food; + } + } + // set modal header html + if (!farm.name) { + farm = farm[0]; + } + + if (!primary_operation) { + primary_operation = "N/A"; + } else { + primary_operation = capitalize_words(primary_operation); + } + + + $('#modal_header').html('

' + farm.name + '

'); + + // set modal tab 1 html + $('#tab_1_title').html('Home'); + $('#tab_1').html( + '

Basic Information:' + '

' + + '

Growing Method: ' + getGrowingMethod(farm) + '

' + + '

Operation: ' + getOperation(farm) + '

' + + '

Selling Method: ' + getSellingMethod(farm) + '

' + + '

Primary Operation: ' + primary_operation + '

' + ); + + // set modal tab 2 html + $('#tab_2_title').html('Contact'); + var tab_2_html = ''; + if(farm.address){ + tab_2_html = tab_2_html + '

' + farm.address + '

'; + } + if(farm.phone){ + tab_2_html = tab_2_html + '

' + farm.phone + '

'; + } + tab_2_html = tab_2_html+'
' ; + if(farm.url){ + tab_2_html = tab_2_html + ' Visit our webpage '; + } + if(farm.facebook){ + tab_2_html = tab_2_html + '| Facebook '; + } + if(farm.twitter){ + tab_2_html = tab_2_html + '| Twitter'; + } + tab_2_html += '
'; + + + $('#tab_2').html( + tab_2_html + ); + + // set modal tab 3 html + $('#tab_3_title').html('Media'); + $('#tab_3').html( + '

Pictures/Video

' + + '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

' + ); + + + // show button + $('#contact_button').show(); + $('#recipe_link_button').hide(); + + // show modal + $("#generic_modal").modal() +} + +function setAndShowRecipeModal(recipe) { + // set modal header html + $('#modal_header').html( + '

' + recipe.label + '

' + + '

' + recipe.source + '

' + ); + // compile tab 1 data + var ingredient_list = '"; + // compile tab 2 data + var health_list = '"; + // compile tab 3 data + var nutrient_list = '"; + // compile tab 4 data + // set all modal tabs html content + $('#tab_1_title').html('Ingredients'); + $('#tab_1').html(ingredient_list); + $('#tab_2_title').html('Health Information'); + $('#tab_2').html(health_list); + $('#tab_3_title').html("Nutrients"); + $('#tab_3').html(nutrient_list); + // hide button + $('#contact_button').hide(); + $('#recipe_link_button').show(); + $('#recipe_link_tag').attr("href", recipe.url); + // show modal + $("#generic_modal").modal() +} \ No newline at end of file diff --git a/app/assets/javascripts/recipe_api.js b/app/assets/javascripts/recipe_api.js new file mode 100644 index 0000000..b4e5634 --- /dev/null +++ b/app/assets/javascripts/recipe_api.js @@ -0,0 +1,80 @@ +//Save for Recipe pages, not in use right now + + +/************************* + * RECIPE API FUNCTIONS * + * ***********************/ +function callFood2Fork(food_string, checkRecipeValues) { + // clear the html to get rid of old recipes + $("#recipe_grid").html(""); + var call_url = "https://api.edamam.com/search?q=" + food_string + "&app_id=" + edemam_app_id + "&app_key=" + edemam_app_key; + var health_query = ""; + for (var i = 0; i < checkRecipeValues.length; i++) { + if (i != checkRecipeValues.length - 1) { + health_query += checkRecipeValues[i] + ',%20'; + } + } + if (checkRecipeValues.length > 0) { + call_url += "&healthLabels=" + health_query; + } + // make call + $.ajax({ + type: "GET", + url: call_url, + headers: { + // "Access-Control-Allow-Origin":"*" + "more": true, + }, + dataType: 'json', + //contentType: 'text/plain;charset=UTF-8', + crossDomain: true, + //async: false, + success: function(result) { + if (result != null && result.hits.length > 0) { + handleRecipeAPICall(result.hits); + } else { + alert("Your search query returned no results . . . ") + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + console.log("Status: " + textStatus); + console.log("Error: " + errorThrown); + } + }); +} + +function handleRecipeAPICall(recipe_list) { + + // reset recipe list + recipes = {}; + + // iterate through + for (var i = 0; i < recipe_list.length; i++) { + + // get current recipe and id + var current_recipe = recipe_list[i].recipe; + var id = "recipe_" + (i + 1); + + // put in recipe list + recipes[id] = current_recipe; + + // add html + $('#recipe_grid').append( + '
' + + '' + + '
' + + '

' + current_recipe.label + '

' + + '
' + current_recipe.source + '
' + + 'Go to recipe' + + '' + ); + + // on click to show modal + $('#' + id).on('click', function() { + var new_id = this.getAttribute('id'); + // alter html in modal + setAndShowRecipeModal(recipes[new_id]); + }); + } +} \ No newline at end of file diff --git a/app/assets/javascripts/search.js b/app/assets/javascripts/search.js new file mode 100644 index 0000000..ca8e922 --- /dev/null +++ b/app/assets/javascripts/search.js @@ -0,0 +1,169 @@ +// return true if a string is empty or only contains whitespace +function isEmpty(str) { + return (str.length === 0 || !str.trim()); +} + + +// return true if a string is not empty and contains more than whitespace +function containsChars(str) { + return !isEmpty(str); +} + + +/** + Set up on_click for search farm + **/ +function set_up_search() { + + var input = document.getElementById("search-text-home"); + if(input != null){ + input.addEventListener("keypress", function(event) { + if (event.keyCode == 13) { + event.preventDefault(); + document.getElementById("search-button-home").click(); + } + }, false); + } + + // set up farm search + $('#search-button-home').on('click', function() { + var farms = []; + var text = $('#search-text-home').val(); + var call_url = "/farms/farm_json"; + //Make an ajax call to retrieve information about farms + callIndexApi(call_url, handlesearch, text) + }) +} + + + + +/** + Handle the search for farms + @params + result: result of ajax call, supposed to be a json array + text: the search text + **/ +function handlesearch(result, text) { + var farms = []; + if(text==null){ + Visualize_Farm(result); + return; + } + for (var i = 0; i < result.length; i++) { + // Convert the json into a string + var farm_string = JSON.stringify(result[i]); + // search whether the string include the text + if ((farm_string.toLowerCase()).includes(text.toLowerCase())) { + farms.push(result[i]); + } + + + } + Visualize_Farm(farms); + return farms; + + +} + +/** + visualize the farms cards in the front page + @params + result: result or filtered result of ajax call, supposed to be a json array + **/ +function Visualize_Farm(result) { + //For debugging + console.log(result) + /*global $*/ + // clear contents of card-grid before displaying results of search + document.getElementById("card-grid").innerHTML = ""; + + for (var i = 0; i < result.length; i++) { + + var cur_farm = result[i]; + var id = "farm_" + cur_farm.id; // create id + + var farm_name = cur_farm.name; + var farm_address = cur_farm.address; + var farm_phone = cur_farm.phone; + var farm_url = cur_farm.url; + let farm_id = cur_farm.id; + + // create the farm card for the current farm + var farm_card = document.createElement("div"); + $(farm_card).addClass("card"); + //var card_link = document.createElement("a"); + //$(farm_card).attr("href", BASE_URL+'map'); // add and format website link + $(farm_card).attr('id', id); + + + + // if the farm has a name, add it to the card + if (containsChars(farm_name)) { + var card_name = document.createElement("h3"); + $(card_name).addClass("card-name"); + card_name.append(farm_name); + farm_card.append(card_name); + } + + // if the farm has an address phone or url... + if (containsChars(farm_address) || containsChars(farm_phone) || containsChars(farm_url) ) { + + // if the farm has an address, add it to the card + if (containsChars(farm_address)) { + var card_address = document.createElement("p"); + card_address.append(farm_address); + farm_card.append(card_address); + } + + // if the farm has a phone and a url, add them to the card with a pipe between them + if (containsChars(farm_phone) && containsChars(farm_url)) { + var card_contact_info = document.createElement("p"); + var card_phone_link = document.createElement("a"); + var card_url_link = document.createElement("a"); + + card_phone_link.append(farm_phone); + $(card_phone_link).attr("href", 'tel:'+farm_phone); // add and format phone link + + card_url_link.append(farm_url); + $(card_url_link).attr("href", 'http://'+farm_url); // add and format website link + + card_contact_info.append(card_phone_link); + card_contact_info.append(" | "); // spacer between phone and url + card_contact_info.append(card_url_link); + farm_card.append(card_contact_info); + } + + else if (containsChars(farm_phone)) { + var card_phone = document.createElement("p"); + var card_phone_link = document.createElement("a"); + + card_phone_link.append(farm_phone); + $(card_phone_link).attr("href", 'tel:'+farm_phone); // add and format phone link + + card_phone.append(card_phone_link); + farm_card.append(card_phone); + } + + else if (containsChars(farm_url)) { + var card_url = document.createElement("p"); + var card_url_link = document.createElement("a"); + + card_url_link.append(farm_url); + $(card_url_link).attr("href", 'http://'+farm_url); // add and format website link + + card_url.append(card_url_link); + farm_card.append(card_url); + } + } + + // add the farm_card to the card-grid + $('#card-grid').append(farm_card); + + //Add the link to each farmers own page + $('#' + id).on('click', function() { + window.location.href = BASE_URL+'farms/'+farm_id + }); + + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/_variables.scss b/app/assets/stylesheets/_variables.scss new file mode 100644 index 0000000..4bd8be5 --- /dev/null +++ b/app/assets/stylesheets/_variables.scss @@ -0,0 +1,33 @@ +/* GLOBALS */ + +$font-stack: Helvetica, Arial, sans-serif; + +$green: rgba(105, 139, 105, 1); +$light-grey: #333333; +$dark-grey: #1f1f1f; + +/* CARDS */ +$odd-card-background-color: #e2e2e2; +$even-card-background-color: rgba(105, 139, 105, .6); // this is $green with some transparency + +$odd-card-text-color: black; +$odd-card-text-link-color: $odd-card-text-color; + + +$even-card-text-color: black; +$even-card-text-link-color: $even-card-text-color; + +/* SEARCH */ +$search-bar-background-color: #e2e2e2; +$search-bar-border-color: #dbdbdb; +$search-bar-text-color: black; + +$search-button-background-color: $green; +$search-button-text-color: #fafafa; + +/* FOOTER */ +$social-icons-text-color: $light-grey; +$social-icons-color: rgba(255, 255, 255, 1); +$social-icons-hover-color: rgba(255, 255, 255, 0.6); + +$site-info-text-color: rgba(255, 255, 255, 0.8); \ No newline at end of file diff --git a/app/assets/stylesheets/active_admin.scss b/app/assets/stylesheets/active_admin.scss new file mode 100644 index 0000000..076fcd7 --- /dev/null +++ b/app/assets/stylesheets/active_admin.scss @@ -0,0 +1,17 @@ +// SASS variable overrides must be declared before loading up Active Admin's styles. + +// To view the variables that Active Admin provides, take a look at +// `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the +// Active Admin source. + +// For example, to change the sidebar width: +$sidebar-width: 242px; + +// Active Admin's got SASS! +@import "active_admin/mixins"; +@import "active_admin/base"; + +// Overriding any non-variable SASS must be done after the fact. +// For example, to change the default status-tag color: + + .status_tag { background: #6090DB; } diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f9cd5b3..35c4a1e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,15 +1,5 @@ /* - * 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 - */ +*= require_self +*= require_tree +*= stub "active_admin" +*/ \ No newline at end of file diff --git a/app/assets/stylesheets/card_grid.scss b/app/assets/stylesheets/card_grid.scss new file mode 100644 index 0000000..c5e5e86 --- /dev/null +++ b/app/assets/stylesheets/card_grid.scss @@ -0,0 +1,116 @@ +@import 'variables'; + +.card-grid { + display: grid; + grid-template-columns: 1fr; + grid-row-gap: 15px; + padding-bottom: 20px; + + text-align: center; + + div:nth-child(odd) { + background-color: $odd-card-background-color; + color: $odd-card-text-color; + + a { + color: $odd-card-text-link-color; + } + } + + div:nth-child(even) { + background-color: $even-card-background-color; + color: $even-card-text-color; + + a { + color: $even-card-text-link-color; + } + } + + .card { + font-family: $font-stack; + padding: 4px 0; + + + &:hover { + cursor: pointer; + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); + } + + .card-name { + font-size: 1.2em; + margin: 0; + padding: 0; + color: inherit; + } + + p { + font-size: 1em; + line-height: 1.5em; + padding: 0; + margin: 0; + color: inherit; + } + + a { + text-decoration: none; + &:hover { + text-decoration: underline; + } + } + } +} + +// Number of grid columns increases by 1 as screen width increases by 400px + +/* 2 columns for medium screens */ +@media screen and (min-width: 800px) { + .card-grid { + grid-template-columns: 1fr 1fr; + grid-gap: 20px; + } + + .card-grid-wrapper { + display: grid; + grid-template-columns: 80px 1fr 80px; + } + +} + +/* 3 columns for large screens */ +@media screen and (min-width: 1200px) { + .card-grid { + grid-template-columns: 1fr 1fr 1fr; + grid-gap: 20px; + } + + .card-grid-wrapper { + display: grid; + grid-template-columns: 80px 1fr 80px; + } +} + +/* 4 columns for larger screens */ +@media screen and (min-width: 1600px) { + .card-grid { + grid-template-columns: 1fr 1fr 1fr 1fr; + grid-gap: 20px; + } + + .card-grid-wrapper { + display: grid; + grid-template-columns: 80px 1fr 80px; + } +} + +/* 5 columns for huge screens */ +@media screen and (min-width: 2000px) { + .card-grid { + grid-template-columns: 1fr 1fr 1fr 1fr 1fr; + grid-gap: 20px; + } + + .card-grid-wrapper { + display: grid; + grid-template-columns: 80px 1fr 80px; + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/farm_search_bar.scss b/app/assets/stylesheets/farm_search_bar.scss new file mode 100644 index 0000000..e0bca9a --- /dev/null +++ b/app/assets/stylesheets/farm_search_bar.scss @@ -0,0 +1,44 @@ +@import 'variables'; + +// Spaces above and below search row +.search-row { + margin-top: 20px; + margin-bottom: 20px; +} + +// Centered search bar +.search-bar { + display: flex; + justify-content: center; + + label, p { + display: none; + } +} + +// Search text field will fill 70% of screen width and has maxiumum width of 600px +.search-field { + padding: 8px 15px; + background: $search-bar-background-color; + border: 0px solid $search-bar-border-color; + color: $search-bar-text-color; + width: 70%; + max-width: 600px; + font-size: 16px; +} + +.search-button { + position: relative; // Search button sits immediately next to search text field + padding: 6px 15px; + left: -8px; + border: 2px solid $search-button-background-color; + background-color: $search-button-background-color; + color: $search-button-text-color; + cursor: pointer; + font-size: 13px; +} + +.search-button:hover { + background-color: $search-button-text-color; // colors of button are switched on hover + color: $search-button-background-color; +} \ No newline at end of file diff --git a/app/assets/stylesheets/map.scss b/app/assets/stylesheets/map.scss new file mode 100644 index 0000000..46832e5 --- /dev/null +++ b/app/assets/stylesheets/map.scss @@ -0,0 +1,6 @@ +// Map has minimum height of 500px and will otherwise be 80% of the viewport height; spans width of screen always +.farm-map { + width: 100%; + min-height: 500px; + height: 80vh; +} \ No newline at end of file diff --git a/app/assets/stylesheets/signup-form.scss b/app/assets/stylesheets/signup-form.scss new file mode 100644 index 0000000..d168ac7 --- /dev/null +++ b/app/assets/stylesheets/signup-form.scss @@ -0,0 +1,9 @@ +@import 'variables'; + +.signup-form { + display: grid; + grid-template-columns: 1fr 4fr 1fr; + font-family: $font-stack; +} + + diff --git a/app/assets/stylesheets/static_pages.scss b/app/assets/stylesheets/static_pages.scss new file mode 100644 index 0000000..c9ac0a5 --- /dev/null +++ b/app/assets/stylesheets/static_pages.scss @@ -0,0 +1,269 @@ +@import 'variables'; + +*, +*::before, +*::after { + box-sizing: border-box; +} + +html { + height: 100%; + font-family: $font-stack; +} + +body { + margin: 0; + height: 100%; +} + +// screen reader only content is hidden +.sr-only { + display: none; +} + +.grid { + display: grid; + grid-template-columns: 1fr; + grid-template-columns: 100%; + min-height: 100%; + grid-template-rows: auto auto 1fr auto; /* this forces footer to bottom of page by making yielded content take up maximum height available*/ +} + +header { + background: white; + text-align: center; + position: fixed; + z-index: 999; + width: 100%; + height: 80px; +} + +.logo { + position: relative; + height: 80px; + + img { + max-height: 80%; // logo fills 80% height of header total height and is vertically centered + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: auto; + height: auto; + margin: auto; + } +} + +.nav-toggle { + position: absolute !important; + top: -9999px !important; + left: -9999px !important; +} + +.nav-toggle-label { + position: absolute; + top: 0; + right: 0; + margin-right: 1em; + height: 100%; + display: flex; + align-items: center; + cursor: pointer; +} + + +/* Create hamburger menu */ +.nav-toggle-label span, +.nav-toggle-label span::before, +.nav-toggle-label span::after { + display: block; + background: black; + height: 2px; + width: 2em; + border-radius: 2px; + position: relative; +} + +.nav-toggle-label span::before, +.nav-toggle-label span::after { + content: ''; + position: absolute; +} + +.nav-toggle-label span::before { + bottom: 7px; +} + +.nav-toggle-label span::after { + top: 7px; +} +/* end of hamburger menu */ + +nav { + position: absolute; + text-align: right; + top: 100%; + left: 0; + background: white; + width: 100%; + transform: scale(1, 0); + transform-origin: top; + transition: transform 400ms ease-in-out; + + ul { + margin: 0; + padding: 0; + list-style: none; + } + + li { + margin-bottom: 1em; + margin-left: 1em; + } + + a { + color: black; + text-decoration: none; + font-size: 13px; + margin-right: 1em; + text-transform: uppercase; + opacity: 0; + transition: opacity 150ms ease-in-out; + font-family: $font-stack; + font-weight: 600; + font-style: normal; + letter-spacing: 2px; + line-height: 1em; + + &:hover { + color: $green; + } + } +} + +.nav-toggle:checked~nav { + transform: scale(1, 1); +} + +.nav-toggle:checked~nav a { + opacity: 1; + transition: opacity 250ms ease-in-out 250ms; +} + +/* HERO IMAGE */ + +.hero { + align-items: center; + background-color: black; + background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("/assets/hero.jpg"); + height: 50vh; + display: flex; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + + h2 { + color: white; + margin: auto; + font-size: 60px; + text-align: center; + font-family: $font-stack; + } +} + +/* FOOTER */ +footer { + display: grid; + grid-template-columns: 1fr; + left: 0px; + bottom: 0px; + width: 100%; +} + +.social-icons { + background-color: $light-grey; + text-align: center; +} + +.list-social-icons { + padding: 10px 0; + margin: 0; + list-style: none; + + li { + display: inline-block; + } + a { + color: $social-icons-color; + + &:hover { + color: $social-icons-hover-color; + } + } + .fa-2x { + font-size: 1rem; + } + .social-icon-text { + color: $social-icons-text-color; + } +} + +.site-info { + padding: 10px 0; + background-color: $dark-grey; + color: $site-info-text-color; + font-size: 14px; + font-style: normal; + font-weight: 400; + letter-spacing: 2px; + text-transform: uppercase; + font-family: $font-stack; + text-align: center; + + a { + text-decoration: none; + color: inherit; + margin-left: 14px; + } +} + +/* SCREENS WIDER THAN 800PX */ + +@media screen and (min-width: 800px) { + .nav-toggle-label { + display: none; + } + + header { + display: grid; + grid-template-columns: 1fr auto minmax(600px, 3fr) 1fr; + } + + .logo { + grid-column: 2 / 3; + } + + nav { + all: unset; + grid-column: 3 / 4; + display: flex; + justify-content: flex-end; + align-items: center; + text-align: left; + } + + nav ul { + display: flex; + } + + nav li { + margin-left: 3em; + margin-bottom: 0; + } + + nav a { + opacity: 1; + margin-right: 0; + } +} \ No newline at end of file diff --git a/app/controllers/farms_controller.rb b/app/controllers/farms_controller.rb index 8aa7ae6..982bd8c 100644 --- a/app/controllers/farms_controller.rb +++ b/app/controllers/farms_controller.rb @@ -2,13 +2,16 @@ class FarmsController < ApplicationController before_filter :skip_authorization before_action :authenticate + skip_before_action :verify_authenticity_token #disable security check? # before_action :authenticate_farm! + +#This is not what the show supposed to look like, but we rely on it for store the farm json +#It need to be changed to a totally different format in the future + def show # @farm = Farm.find(parmas[:id]) # authorize @farm - - @show_farms = Farm.where(approved: true) @invalid_farms = Farm.where(approved: false) if params[:id] == "farm_json" @@ -17,15 +20,19 @@ def show return review elsif params[:id] == "approved" return approved + else + @farm = Farm.find(params[:id]) end end +#This is also not what a index page should look like def index #@farm = Farm.all # authorize @farm @show_farms = Farm.where(approved: true) + # @operation_farms = Farm.where(operation: beef) # @farms_json = buildJson @show_farms # puts @farms_json end @@ -75,13 +82,25 @@ def approved end def farm_json - @show_farms = Farm.where(approved: true) - @farms_json = buildJson @show_farms - end - - def buildJson farms - render :json => farms + show_farms = Farm.where(approved: true).includes([:operations, :growing_methods, :selling_methods]) + render json: show_farms.as_json(include: [:operations, :growing_methods, :selling_methods]) + end + + def farm_by_operation + show_farms = [] + Operation.all.each do |o| + if params[:farms][:operations].include? o.food + show_farm = o.farms + show_farm.each do |farm| + if (!show_farms.include? farm) + show_farms.push(farm) + end + end + end + end + render json: show_farms.as_json(include: [:operations, :growing_methods, :selling_methods]) end + def approve id = params[:item_id] @@ -121,7 +140,10 @@ def authenticate #private def farm_params - params.require(:farm).permit(:name, :address, :url, :phone, :facebook, :instagram, :twitter, :email, :contact_name, :year, :statement, :other_media, :link_to_cert, :growth_promoter, :antibiotic, :fav_activity, :why_farm) + params.require(:farm).permit(:name, :address, :url, :phone, :facebook, + :instagram, :twitter, :email, :contact_name, :year, :statement, + :other_media, :link_to_cert, :growth_promoter, :antibiotic, + :fav_activity, :why_farm, :operations, :primary_operation_id, :password) end private diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb new file mode 100644 index 0000000..9ec85e7 --- /dev/null +++ b/app/controllers/static_pages_controller.rb @@ -0,0 +1,13 @@ +class StaticPagesController < ApplicationController + def view2 + end + + def map + end + + def recipes + end + + def farmer + end +end diff --git a/app/decorators/ui_decorator.rb b/app/decorators/ui_decorator.rb new file mode 100644 index 0000000..19876eb --- /dev/null +++ b/app/decorators/ui_decorator.rb @@ -0,0 +1,13 @@ +class UiDecorator < Draper::Decorator + delegate_all + + # Define presentation-specific methods here. Helpers are accessed through + # `helpers` (aka `h`). You can override attributes, for example: + # + # def created_at + # helpers.content_tag :span, class: 'time' do + # object.created_at.strftime("%a %m/%d/%y") + # end + # end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..a2f4870 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,3 @@ module ApplicationHelper + end diff --git a/app/helpers/static_pages_helper.rb b/app/helpers/static_pages_helper.rb new file mode 100644 index 0000000..577e138 --- /dev/null +++ b/app/helpers/static_pages_helper.rb @@ -0,0 +1,23 @@ +module StaticPagesHelper + + # Returns the full title on a per-page basis. + def full_title(page_title = '') + base_title = "Local Foods Connection" + if page_title.empty? + base_title + else + page_title + " | " + base_title + end + end + + # Returns the hero image text on a per-page basis. + def hero_text(text = '') + default_text = "Explore Local Farms" + if text.empty? + default_text + else + text + end + end + +end diff --git a/app/models/farm.rb b/app/models/farm.rb index 04de6e4..81c6537 100644 --- a/app/models/farm.rb +++ b/app/models/farm.rb @@ -1,24 +1,23 @@ class Farm < ActiveRecord::Base - # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable - - has_and_belongs_to_many :operations + has_many :farms_operations + has_many :operations, through: :farms_operations has_and_belongs_to_many :growing_methods has_and_belongs_to_many :selling_methods has_and_belongs_to_many :markets + belongs_to :primary_operation, class_name: "Operation", foreign_key: "primary_operation_id" enum role: [:farm, :admin] after_initialize :set_default_role, :if => :new_record? def set_default_role - self.role ||= :farm + self.role ||= :farm end def admin? - self.role == "admin" + self.role.to_sym == :admin #Converted self.role to symbol since it's stored in self as a string end - end diff --git a/app/models/farms_operation.rb b/app/models/farms_operation.rb new file mode 100644 index 0000000..04d429d --- /dev/null +++ b/app/models/farms_operation.rb @@ -0,0 +1,4 @@ +class FarmsOperation < ApplicationRecord + belongs_to :farm + belongs_to :operation +end diff --git a/app/models/growing_method.rb b/app/models/growing_method.rb index e2505e6..417a7a0 100644 --- a/app/models/growing_method.rb +++ b/app/models/growing_method.rb @@ -1,3 +1,8 @@ class GrowingMethod < ApplicationRecord - has_and_belongs_to_many :farms + has_and_belongs_to_many :farms + + # To display name of growing_method in admin page + def display_name + grow_method + end end diff --git a/app/models/market.rb b/app/models/market.rb index 46e08aa..71babd5 100644 --- a/app/models/market.rb +++ b/app/models/market.rb @@ -1,3 +1,8 @@ class Market < ApplicationRecord - has_and_belongs_to_many :farms + has_and_belongs_to_many :farms + + # To display name of market in admin page + def display_name + location + end end diff --git a/app/models/operation.rb b/app/models/operation.rb index 058d659..d29a6eb 100644 --- a/app/models/operation.rb +++ b/app/models/operation.rb @@ -1,3 +1,9 @@ class Operation < ApplicationRecord - has_and_belongs_to_many :farms + has_many :farms_operations + has_many :farms, through: :farms_operations + + #To display name of the operation in the admin page + def display_name + food + end end diff --git a/app/models/primary_operation.rb b/app/models/primary_operation.rb new file mode 100644 index 0000000..9d7a5fd --- /dev/null +++ b/app/models/primary_operation.rb @@ -0,0 +1,7 @@ +class PrimaryOperation < ApplicationRecord + has_one :operation + + def display_name + food + end +end diff --git a/app/models/selling_method.rb b/app/models/selling_method.rb index d087b01..736bc04 100644 --- a/app/models/selling_method.rb +++ b/app/models/selling_method.rb @@ -1,3 +1,8 @@ class SellingMethod < ApplicationRecord - has_and_belongs_to_many :farms + has_and_belongs_to_many :farms + + # To display selling_method in admin page + def display_name + sell_method + end end diff --git a/app/models/user.rb b/app/models/user.rb deleted file mode 100644 index 4a57cf0..0000000 --- a/app/models/user.rb +++ /dev/null @@ -1,2 +0,0 @@ -class User < ActiveRecord::Base -end diff --git a/app/policies/active_admin/farm_policy.rb b/app/policies/active_admin/farm_policy.rb index 3bc2379..4314600 100644 --- a/app/policies/active_admin/farm_policy.rb +++ b/app/policies/active_admin/farm_policy.rb @@ -31,3 +31,4 @@ def destroy? true end end +end diff --git a/app/views/farms/edit.html.erb b/app/views/farms/edit.html.erb index 359bc60..84f9b9c 100644 --- a/app/views/farms/edit.html.erb +++ b/app/views/farms/edit.html.erb @@ -1,2 +1,6 @@

Edit farm

-<%= render 'index' %> \ No newline at end of file + +

+ Eventually there should be a form to edit fields of the farm if the proper + user is logged in to the site. +

\ No newline at end of file diff --git a/app/views/farms/index.html.erb b/app/views/farms/index.html.erb index 0ae22a3..f04fa0c 100644 --- a/app/views/farms/index.html.erb +++ b/app/views/farms/index.html.erb @@ -1,13 +1,23 @@ - +

Farm Information - +

<%= form_for :farm do |f| %>

<%= f.label :name %>
<%= f.text_field :name %>

- + +

+ <%= f.label :email %>
+ <%= f.text_field :email %> +

+ +

+ <%= f.label :password %>
+ <%= f.text_field :password %> +

+

<%= f.label :address %>
<%= f.text_area :address %> @@ -38,9 +48,22 @@ <%= f.text_field :twitter %>

+

+ Farm Details +

+

+ <%= f.label :growing_methods%>
+ <% #Attempting to make checkboxes out of the growing methods %> + <% GrowingMethod.all.each do |g| f.check_box :g end %> + + +

+ +

<%= f.submit "Submit" %>

<% end %> <%= link_to 'Approved Farms', farms_approved_path %> + diff --git a/app/views/farms/index.html.haml b/app/views/farms/index.html.haml index 6bd26c6..8713b7f 100644 --- a/app/views/farms/index.html.haml +++ b/app/views/farms/index.html.haml @@ -1,4 +1,5 @@ -# This file is app/views/farms/index.html.haml +-# Need to be modified to an actual index page %h1 All Farms %table#show_farms diff --git a/app/views/farms/new.html.erb b/app/views/farms/new.html.erb index e560cb3..409124c 100644 --- a/app/views/farms/new.html.erb +++ b/app/views/farms/new.html.erb @@ -1,43 +1,113 @@ -<%= form_for :farm do |f| %> -

- <%= f.label :name %>
- <%= f.text_field :name %> -

- -

- <%= f.label :address %>
- <%= f.text_area :address %> -

- -

- <%= f.label :url %>
- <%= f.text_field :url %> -

- -

- <%= f.label :phone %>
- <%= f.text_field :phone %> -

- -

- <%= f.label :facebook %>
- <%= f.text_field :facebook %> -

- -

- <%= f.label :instagram %>
- <%= f.text_field :instagram %> -

- -

- <%= f.label :twitter %>
- <%= f.text_field :twitter %> -

- -

- <%= f.submit "Submit" %> -

- <% end %> +<% provide(:title, "New Farm Sign Up") %> +<% provide(:hero, "Register as a Local Farm") %> +
+ +
diff --git a/app/views/farms/show.html.haml b/app/views/farms/show.html.haml index ee0fd0a..9ad41bd 100644 --- a/app/views/farms/show.html.haml +++ b/app/views/farms/show.html.haml @@ -1,4 +1,10 @@ -# in app/views/movies/show.html.haml -%h2 Form Submitted! +-#Need to be modified to a real page introducing farms + +%strong= @farm.name +%strong= @farm.address +%strong= @farm.phone + + + -= link_to 'Back to index', farms_path diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 11c2eb8..a212e9e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,21 @@ - - - Workspace - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> + + + <%= full_title(yield(:title)) %> + + <%= stylesheet_link_tag 'application', media: 'all', + 'data-turbolinks-track': 'reload' %> + + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + <%= favicon_link_tag asset_path('favicon.png'), :rel => 'icon', :type => 'image/png' %> - -<%= yield %> - +
+ <%= render 'shared/header' %> + <%= render 'shared/hero' %> + <%= yield %> + <%= render 'shared/footer' %> +
- + \ No newline at end of file diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb new file mode 100644 index 0000000..9fb3dda --- /dev/null +++ b/app/views/shared/_footer.html.erb @@ -0,0 +1,38 @@ + \ No newline at end of file diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb new file mode 100644 index 0000000..aaa9a90 --- /dev/null +++ b/app/views/shared/_header.html.erb @@ -0,0 +1,21 @@ +
+ + + + +
+ +
\ No newline at end of file diff --git a/app/views/shared/_hero.html.erb b/app/views/shared/_hero.html.erb new file mode 100644 index 0000000..5fdf085 --- /dev/null +++ b/app/views/shared/_hero.html.erb @@ -0,0 +1,3 @@ +
+

<%= hero_text(yield(:hero)) %>

+
\ No newline at end of file diff --git a/app/views/static_pages/farmer.html.erb b/app/views/static_pages/farmer.html.erb new file mode 100644 index 0000000..51a41b5 --- /dev/null +++ b/app/views/static_pages/farmer.html.erb @@ -0,0 +1,6 @@ +<% provide(:title, "Farmer") %> +<% provide(:hero, "Get To Know Our Local Farm") %> + +
+ There will be the Farm's picture on the left hand side. The Farm name at the top with a farm statement below that. Contact and a list of products and growing methods in boxes on the right side. +
diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb new file mode 100644 index 0000000..56caa57 --- /dev/null +++ b/app/views/static_pages/home.html.erb @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + +
+
+
+

Explore Our Farms

+
+
+
+ +
+

Search Local Farms

+ + +
+ + + + + + + +
+ +
+ +
+
+
+ +
+
    +
+
+
+
+ +
+
+

Search Recipes

+
+ +
+ + + + +
+
+ + + + + + + +
+
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/app/views/static_pages/map.html.erb b/app/views/static_pages/map.html.erb new file mode 100644 index 0000000..8377732 --- /dev/null +++ b/app/views/static_pages/map.html.erb @@ -0,0 +1,7 @@ +<% provide(:title, "Map") %> +
+
+

You need to enable JavaScript on this page for the map to work.

+
+ +
diff --git a/app/views/static_pages/view2.html.erb b/app/views/static_pages/view2.html.erb new file mode 100644 index 0000000..d26c305 --- /dev/null +++ b/app/views/static_pages/view2.html.erb @@ -0,0 +1,20 @@ +<% provide(:title, "Home") %> +<% provide(:hero, "Search Local Farms") %> +
+ +
+ +
+ +
+
+
+
+
+ +
\ No newline at end of file diff --git a/bundle-log b/bundle-log new file mode 100644 index 0000000..22a151f --- /dev/null +++ b/bundle-log @@ -0,0 +1,87 @@ +Using rake 12.3.1 +Using concurrent-ruby 1.0.5 +Using i18n 0.9.5 +Using minitest 5.11.3 +Using thread_safe 0.3.6 +Using tzinfo 1.2.5 +Using activesupport 5.0.2 +Using builder 3.2.3 +Using erubis 2.7.0 +Using mini_portile2 2.3.0 +Using nokogiri 1.8.2 +Using rails-dom-testing 2.0.3 +Using crass 1.0.4 +Using loofah 2.2.2 +Using rails-html-sanitizer 1.0.4 +Using actionview 5.0.2 +Using rack 2.0.4 +Using rack-test 0.6.3 +Using actionpack 5.0.2 +Using nio4r 2.3.0 +Using websocket-extensions 0.1.3 +Using websocket-driver 0.6.5 +Using actioncable 5.0.2 +Using globalid 0.4.1 +Using activejob 5.0.2 +Using mini_mime 1.0.0 +Using mail 2.7.0 +Using actionmailer 5.0.2 +Using arbre 1.1.1 +Using coffee-script-source 1.12.2 +Using execjs 2.7.0 +Using coffee-script 2.4.1 +Using method_source 0.9.0 +Using thor 0.20.0 +Using railties 5.0.2 +Using coffee-rails 4.1.1 +Using formtastic 3.1.5 +Using formtastic_i18n 0.6.0 +Using has_scope 0.7.2 +Using responders 2.4.0 +Using inherited_resources 1.8.0 +Using jquery-rails 4.3.3 +Using kaminari-core 1.1.1 +Using kaminari-actionview 1.1.1 +Using activemodel 5.0.2 +Using arel 7.1.4 +Using activerecord 5.0.2 +Using kaminari-activerecord 1.1.1 +Using kaminari 1.1.1 +Using polyamorous 1.3.3 +Using ransack 1.8.8 +Using rb-fsevent 0.10.3 +Using ffi 1.9.23 +Using rb-inotify 0.9.10 +Using sass-listen 4.0.0 +Using sass 3.5.6 +Using sprockets 3.7.1 +Using activeadmin 1.2.1 +Using activemodel-serializers-xml 1.0.2 +Using bcrypt 3.1.11 +Using bundler 1.16.1 +Using cancan 1.6.10 +Using orm_adapter 0.5.0 +Using warden 1.2.7 +Using devise 4.4.3 +Using request_store 1.4.1 +Using draper 3.0.1 +Using temple 0.8.0 +Using tilt 2.0.8 +Using haml 5.0.4 +Using multi_json 1.13.1 +Using jbuilder 2.7.0 +Using json 1.8.6 +Using pundit 1.1.0 +Using rack-cors 0.3.1 +Using sprockets-rails 3.2.1 +Using rails 5.0.2 +Using rdoc 4.3.0 +Using sass-rails 5.0.7 +Using sdoc 0.4.2 +Using simple_form 4.0.0 +Using turbolinks-source 5.1.0 +Using turbolinks 5.1.1 +Using uglifier 4.1.9 +Bundle complete! 21 Gemfile dependencies, 84 gems now installed. +Gems in the groups production, development and test were not installed. +Use `bundle info [gemname]` to see where a bundled gem is installed. diff --git a/config/application.rb b/config/application.rb index c270c61..4080c5a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -33,8 +33,10 @@ class Application < Rails::Application origins '*' resource '*', :headers => :any, :methods => [:get, :post, :options] end + end + config.assets.paths << Rails.root.join("assets", "icons") end - end + end diff --git a/config/database.yml b/config/database.yml index 1c1a37c..d6366a2 100644 --- a/config/database.yml +++ b/config/database.yml @@ -5,21 +5,34 @@ # gem 'sqlite3' # default: &default - adapter: sqlite3 + adapter: postgresql pool: 5 timeout: 5000 development: - <<: *default - database: db/development.sqlite3 + adapter: sqlite3 + pool: 5 + #username: local_foods + # password: + database: lfc_development.sqlite3 + timeout: 5000 + # 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: db/test.sqlite3 + adapter: sqlite3 + pool: 5 + #username: local_foods + #password: + database: lfc_test.sqlite3 + timeout: 5000 production: - <<: *default - database: db/production.sqlite3 + adapter: postgresql + pool: 5 + username: local_foods + password: + database: lfc_production + timeout: 5000 diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e..5f7a458 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -11,7 +11,7 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = true config.action_controller.perform_caching = true # Enable Rack::Cache to put a simple HTTP cache in front of your application @@ -22,14 +22,15 @@ # 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? + # config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = true # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + config.assets.js_compressor = Uglifier.new(harmony: true) # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + config.assets.compile = 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. diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08..21be7a2 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -13,8 +13,11 @@ 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' + + #config.serve_static_files = true #Deprecated in Rails 5.1 + config.public_file_server.enabled = true + #config.static_cache_control = 'public, max-age=3600' #Deprecated in Rails 5.1 + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/config/routes.rb b/config/routes.rb index 01c6ff7..b0700b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,11 @@ Rails.application.routes.draw do + root 'static_pages#view2' + get '/map', to: 'static_pages#map' + get '/recipes', to: 'static_pages#recipes' + get '/farmer', to: 'static_pages#farmer' +# to here + devise_for :farms, ActiveAdmin::Devise.config ActiveAdmin.routes(self) resources :farms @@ -9,17 +15,29 @@ scope '/v1' do scope '/farms' do post '/' => 'farms#farm_json' + + end + end + end + + scope '/api' do + scope '/v1' do + scope '/farms' do + post '/farm_by_operation' => 'farms#farm_by_operation' end end end + root :to => redirect('/admin') get 'farms/review' get 'farms/submission' get 'farms/approved' - + get '/signup', to: 'farms#new' + + post '/farms/new', to: 'farms#create' post 'approve/(:item_id)', to: 'farms#approve', as: :approve post 'reject/(:item_id)', to: "farms#reject", as: :reject -end +end \ No newline at end of file diff --git a/db/migrate/20171012170351_create_farms.rb b/db/migrate/20171012170351_create_farms.rb index 251ad76..fdc0881 100644 --- a/db/migrate/20171012170351_create_farms.rb +++ b/db/migrate/20171012170351_create_farms.rb @@ -8,7 +8,7 @@ def change t.string :facebook t.string :instagram t.string :twitter - + t.string :type_of_farm t.timestamps null: false end end diff --git a/db/migrate/20180228195837_add_new_column_to_my_table.rb b/db/migrate/20180228195837_add_new_column_to_my_table.rb new file mode 100644 index 0000000..d34e833 --- /dev/null +++ b/db/migrate/20180228195837_add_new_column_to_my_table.rb @@ -0,0 +1,5 @@ +class AddNewColumnToMyTable < ActiveRecord::Migration[5.0] + def change + add_column :farms, :farm_type, :string + end +end diff --git a/db/migrate/20180425200411_create_primary_operations.rb b/db/migrate/20180425200411_create_primary_operations.rb new file mode 100644 index 0000000..f53eccc --- /dev/null +++ b/db/migrate/20180425200411_create_primary_operations.rb @@ -0,0 +1,9 @@ +class CreatePrimaryOperations < ActiveRecord::Migration[5.0] + def change + create_table :primary_operations do |t| + t.string :food + + t.timestamps + end + end +end diff --git a/db/migrate/20180507200837_add_primary_operation_id_to_farms.rb b/db/migrate/20180507200837_add_primary_operation_id_to_farms.rb new file mode 100644 index 0000000..332dead --- /dev/null +++ b/db/migrate/20180507200837_add_primary_operation_id_to_farms.rb @@ -0,0 +1,5 @@ +class AddPrimaryOperationIdToFarms < ActiveRecord::Migration[5.0] +def change + add_column :farms, :primary_operation_id, :string + end +end diff --git a/db/migrate/20180510005656_change_primary_operation_id_to_integer.rb b/db/migrate/20180510005656_change_primary_operation_id_to_integer.rb new file mode 100644 index 0000000..90400fa --- /dev/null +++ b/db/migrate/20180510005656_change_primary_operation_id_to_integer.rb @@ -0,0 +1,5 @@ +class ChangePrimaryOperationIdToInteger < ActiveRecord::Migration[5.0] + def change + change_column :farms, :primary_operation_id, 'integer USING CAST(primary_operation_id AS integer)' + end +end diff --git a/db/migrate/20181119031536_users.rb b/db/migrate/20181119031536_users.rb new file mode 100644 index 0000000..eceff31 --- /dev/null +++ b/db/migrate/20181119031536_users.rb @@ -0,0 +1,4 @@ +class Users < ActiveRecord::Migration[5.0] + def change + end +end diff --git a/db/schema.rb b/db/schema.rb index 0d59914..82c9f99 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171205061024) do +ActiveRecord::Schema.define(version: 20181119031536) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace" @@ -34,6 +34,7 @@ t.string "facebook" t.string "instagram" t.string "twitter" + t.string "type_of_farm" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "approved", default: false @@ -58,6 +59,8 @@ t.text "fav_activity" t.text "why_farm" t.integer "role" + t.string "farm_type" + t.integer "primary_operation_id" t.index ["email"], name: "index_farms_on_email", unique: true t.index ["reset_password_token"], name: "index_farms_on_reset_password_token", unique: true end @@ -108,6 +111,12 @@ t.string "food" end + create_table "primary_operations", force: :cascade do |t| + t.string "food" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "selling_methods", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/db/seeds/seed_farm.rb b/db/seeds/seed_farm.rb index cf3bd92..015d577 100644 --- a/db/seeds/seed_farm.rb +++ b/db/seeds/seed_farm.rb @@ -6,25 +6,54 @@ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) -Farm.create!(email: 'admin@example.com', password: 'password', - password_confirmation: 'password', role: 1) \ - if Rails.env.development? +Farm.create(email: 'admin@example.com', password: 'password', + password_confirmation: 'password', role: 1) + # if Rails.env.development? + +# farm_list = [ +# ["Uncle Bill's Farm", "123 Broad St.", "unclebill.com", "515123456", \ +# "Uncle Bill's Farm", "uncle_bill_farm", "uncle_bill_farm", true, \ +# "unclebill@example.com", "ubpassword", "ubpassword", 0], +# ["Uncle Joe's Farm", "1205 Main St.", "unclejoe.com", "641234123", "", \ +# "uncle_joe_farm", "", true, "unclejoe@example.com", "ujpassword", \ +# "ujpassword", 0], +# ["Aunt Maria's Farm", "1641 Park St.", "auntmaria.com", "5150009999", \ +# "Aunt Maria's Farm", "auntmaria_farm", "auntmaria_farm", false, \ +# "auntmaria@example.com", "awpassword", "awpassword", 0], +# ["Aunt Maria's Farm", "1641 Park St.", "auntmaria.com", "5150009999", \ +# "Aunt Maria's Farm", "auntmaria_farm", "auntmaria_farm", true, \ +# "auntmaria1@example.com", "awpassword", "awpassword", 0] + +# ] + +# farm_list.each do |name, address, url, phone, facebook, instagram, twitter, approved, email, password, password_confirmation| +# Farm.create!( name: name, address: address, url: url, phone: phone, +# facebook: facebook, instagram: instagram, twitter: twitter, +# approved: approved, email: email, password: password, +# password_confirmation: password_confirmation) +# end farm_list = [ - ["Uncle Bill's Farm", "123 Broad St.", "unclebill.com", "515123456", \ - "Uncle Bill's Farm", "uncle_bill_farm", "uncle_bill_farm", true, \ - "unclebill@example.com", "ubpassword", "ubpassword", 0], - ["Uncle Joe's Farm", "1205 Main St.", "unclejoe.com", "641234123", "", \ - "uncle_joe_farm", "", true, "unclejoe@example.com", "ujpassword", \ - "ujpassword", 0], - ["Aunt Maria's Farm", "1641 Park St.", "auntmaria.com", "5150009999", \ - "Aunt Maria's Farm", "auntmaria_farm", "auntmaria_farm", false, \ - "auntmaria@example.com", "awpassword", "awpassword", 0] -] - -farm_list.each do |name, address, url, phone, facebook, instagram, twitter, approved, email, password, password_confirmation| +["Compass Plant CSA", "2039 N. Penrose Street. Grinnell, IA 50112", "", \ + "641-990-6832", "ladunham@wildblue.net", "cspassword", "cspassword", true ], +["Doty Angus Cattle Co1", "304 Chapman Street, Malcom, IA", \ + "www.beefforyourfreezer.com", "641-528-4049", "dotyangus@yahoo.com", "dapassword", "dapassword", true], +["Grinnell Heritage Farm1, Inc.", "1933 Penrose St. Grinnell, IA 50112", \ + "www.grinnellheritagefarm.com", "641-990-0018", \ + "grinnellheritagefarm@gmail.com", "ghpassword","ghpassword", true], +["Middle Way Farm", "3633 Hwy. 146, Grinnell, IA 50112", \ + "www.middlewayfarm.com", "641-821-0753", \ + "middlewayfarmer@gmail.com", "mypassword", "mypassword", true], +["Olson Garden Market", "5809 Hwy. T38N, Grinnell, IA 50112", \ + "", "641-990-6605", \ + "kerriolson56@gmail.com", "ogpassword", "ogpassword", true], +["Uncle Bill’s Farm", "244 400th Ave Grinnell, IA 50112", \ + "www.unclebillsfarm.com", "641-236-7043", \ + "unclebillsfarm@hotmail.com", "ubpassword", "ubpassword", true]] + + + +farm_list.each do |name, address, url, phone, email, password, password_confirmation, approved| Farm.create!( name: name, address: address, url: url, phone: phone, - facebook: facebook, instagram: instagram, twitter: twitter, - approved: approved, email: email, password: password, - password_confirmation: password_confirmation) + email: email, password: password, password_confirmation: password_confirmation, approved: approved, ) end diff --git a/db/seeds/seed_operation.rb b/db/seeds/seed_operation.rb index 9d62009..12e4bc8 100644 --- a/db/seeds/seed_operation.rb +++ b/db/seeds/seed_operation.rb @@ -1,4 +1,4 @@ -operation_list = ["fruit", "vegetables", "dairy", "pork", "chicken", "turkey", "lamb", "duck", "agritourism", "hay", "row crop"] +operation_list = ["egg", "beef", "fruit", "vegetables", "dairy", "pork", "chicken", "turkey", "lamb", "duck", "agritourism", "hay", "row crop", "food pantry"] operation_list.each do |food| Operation.create!(food: food) diff --git a/db/seeds/seed_primary_operation.rb b/db/seeds/seed_primary_operation.rb new file mode 100644 index 0000000..ab8aed2 --- /dev/null +++ b/db/seeds/seed_primary_operation.rb @@ -0,0 +1,6 @@ + +operation_list = ["fruit", "vegetables", "dairy", "pork", "chicken", "turkey", "lamb", "duck", "agritourism", "hay", "row crop", "food pantry"] + +operation_list.each do |food| + PrimaryOperation.create!(food: food) +end \ No newline at end of file diff --git a/instructor_comments b/instructor_comments new file mode 100644 index 0000000..0adc37a --- /dev/null +++ b/instructor_comments @@ -0,0 +1 @@ +On the map, the icons representing contributing farms cannot bounce or move. This can be annoying for most users and is a potential accessibility issue for a variety of users. diff --git a/javascript_app/farm.jpg b/javascript_app/farm.jpg deleted file mode 100644 index 5101330..0000000 Binary files a/javascript_app/farm.jpg and /dev/null differ diff --git a/javascript_app/index.css b/javascript_app/index.css deleted file mode 100644 index b9a293b..0000000 --- a/javascript_app/index.css +++ /dev/null @@ -1,129 +0,0 @@ -#map { - border-radius: .1cm; - height: 70vh; - width: 100%; -} - -.section-title { - margin: 0px !important; -} - -.jumbotron { - padding-top: 5px !important; - padding-bottom: 5px !important; -} -.search { - margin: 0cm 0cm .25cm 0cm; - width: 100%; -} - -.search-recipes { - margin: 0px !important; - width: 100%; -} -.category-button { - margin: 0cm 0cm .25cm 0cm !important; -} -.list-group-item { - width: 90%; - margin: 5% 5% 5% 5% !important; - padding: 10px 15px 10px 15px; - border-radius: 10px !important; - -webkit-box-shadow: 5px 5px 15px rgba(0,0,0,0.4); - -moz-box-shadow: 5px 5px 15px rgba(0,0,0,0.4); -} -.list-group-item:hover { - background-color: #eeeeee; -} - -.list-group { - height: 70vh; - overflow: hidden; - -webkit-animation: autoScrolling 5s linear infinite; - overflow-y: scroll !important; -} -/*.col-md-4 { - padding: 0% 5% 0% 5%; -} - -.col-md-8 { - padding: 0% 5% 0% 5%; -}*/ - -.search-container { - padding: 2%; -} - -.content-container { - padding: 2% !important; -} - -.scrollmenu { - background-color: #ffffff; - overflow: auto; - white-space: nowrap; -} - -.scrollmenu-item { - display: inline-block; - margin: 10px; - border-radius: 15px; - width: 22vw; - -webkit-box-shadow: 5px 5px 15px rgba(0,0,0,0.4); - -moz-box-shadow: 5px 5px 15px rgba(0,0,0,0.4); - - -webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */ - -moz-animation: fadein 2s; /* Firefox < 16 */ - -ms-animation: fadein 2s; /* Internet Explorer */ - -o-animation: fadein 2s; /* Opera < 12.1 */ - animation: fadein 2s; -} -.scrollmenu-item-section { - padding: 10px; -} - -.scrollmenu-item:hover { - background-color: #eeeeee; -} - -.recipe_image { - border-top-left-radius: 15px; - border-top-right-radius: 15px; -} - -@keyframes fadein { - from { opacity: 0; } - to { opacity: 1; } -} - -/* Firefox < 16 */ -@-moz-keyframes fadein { - from { opacity: 0; } - to { opacity: 1; } -} - -/* Safari, Chrome and Opera > 12.1 */ -@-webkit-keyframes fadein { - from { opacity: 0; } - to { opacity: 1; } -} - -/* Internet Explorer */ -@-ms-keyframes fadein { - from { opacity: 0; } - to { opacity: 1; } -} - -.modal-image { - width: 40vw; - padding: 15px; -} - -.modal-style { - margin: 15px !important; -} - -.tab-pane { - height: 35vh !important; - overflow-y: scroll !important; -} diff --git a/javascript_app/index.html b/javascript_app/index.html deleted file mode 100644 index 10b12f6..0000000 --- a/javascript_app/index.html +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - -
-
-

Local Foods Connection

-

Explore farms in the Poweshiek County area!

-
-
- - -
-

Explore Local Farms

- - - - -
- - - - - - - -
- - -
- - -
-
-
- - -
-
    -
-
-
-
- - -
-
-

Search Recipes

-
- - -
- - - - -
- -
- -
-
-
- - - - - - - - - diff --git a/javascript_app/index.js b/javascript_app/index.js deleted file mode 100644 index 3a3044e..0000000 --- a/javascript_app/index.js +++ /dev/null @@ -1,355 +0,0 @@ -var map; -var geocoder; -var farms = {}; -var recipes = {}; -// api keys -var edemam_app_id = "c1a85afb"; -var edemam_app_key = "0bf8d80e45004f66c8d4a9e6a523f14f"; -var lfc_key = "YAS0sY2rbi"; - -init(); - -/******** - * INIT * - ********/ - -function init() { - - // set up recipe search - document.getElementById("search_recipes").onclick = function() { - var text = $('#recipe_search_text').val(); - text = text.split(' ').join('%20') - if (text != "") { - callFood2Fork(text); - } - } - - // set up farm search - document.getElementById("search_farm").onclick = function() { - var text = $('#search_farm_text').val(); - if (text != "") { - // call search api here - } - } - - // callFood2Fork(["peas","carrots"]); -} - -/************* - * INIT MAP * - * ***********/ - -function initMap() { - // set location set to grinnell as center of map - var grinnell = { - lat: 41.7434, - lng: -92.7232 }; - - // init map - map = new google.maps.Map(document.getElementById('map'), { - zoom: 10, - center: grinnell - }); - - // init geocoder - geocoder = new google.maps.Geocoder(); - - // call index function for API to load all farms - callIndexApi(); -} - -/**************************************** - * GEOCODING AND ADDING MARKERS FUNCTIONS - * **************************************/ - -function geocodeAddressAndAddMarker(farm) { - var address = farm.address + ", Iowa, 50112" - geocoder.geocode({'address': address}, function(results, status) { - // if OK/200 status, add marker to map, else throw alert. - if (status === 'OK') { - addMarker(farm, results); - } else { - alert('Geocode was not successful for the following reason: ' + status); - } - }); -} - -function addMarker(farm, results) { - - var iconCow = '../icons/64cow.png' - - -// create marker object - var marker = new google.maps.Marker({ - map: map, - animation: google.maps.Animation.BOUNCE, - position: results[0].geometry.location, - title: farm.name, - icon: iconCow - }); - - // data string for display tooltip - var data = farm.name; - // info window for tooltip, contains data - var infowindow = new google.maps.InfoWindow({ - content: data - }); - // add listener to map for marker to display info window - google.maps.event.addListener(marker, 'click', function() { - // open info window - infowindow.open(map,marker); - }); -} - -/*********************** - * FARM API FUNCTIONS * - * *********************/ - -function callIndexApi() { - document.getElementById("farmList").innerHTML = ""; - - var call_url = "http://localhost:3000/farms/farm_json"; - $.ajax({ - type: "GET", - url: call_url, - headers: { - 'X-Auth-Token' : lfc_key - }, - dataType: 'json', - contentType: 'application/json', - crossDomain: true, - async: false, - success: function(result) { - if (result != null || result.length > 0) { - handleIndexCall(result); - } else { - alert("Your search query returned no results . . . ") - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - console.log("Status: " + textStatus); - console.log("Error: " + errorThrown); - } - }); -} - -function handleIndexCall(result) { - - // set to new map - farms = {}; - - for (var i = 0; i < result.length; i++) { - // create id - var id = "farm_" + result[i].id; - // add to map - farms[id] = result[i]; - // append card - $('#farmList').append('
  • ' + - '

    ' + result[i].name + '

    ' + - '
    ' + result[i].address + '
    ' + - '

    CSA, Wholesale, and Farmers Market

    ' + - '' + result[i].url + ' | ' + - '' + result[i].phone + '' + - '
  • ' - ); - // on click to show modal - $('#' + id).on('click', function() { - var new_id = this.getAttribute('id'); - console.log(new_id); - // alter html in modal - setAndShowFarmModal(farms[new_id]); - }); - - // add marker at proper placec - geocodeAddressAndAddMarker(result[i]); - } -} - -/************************* - * RECIPE API FUNCTIONS * - * ***********************/ - -function callFood2Fork(food_string) { - - // clear the html to get rid of old recipes - $("#recipe_grid").html(""); - - // set new url to access - var call_url = "https://api.edamam.com/search?q=" + food_string - + "&app_id=" + edemam_app_id - + "&app_key=" + edemam_app_key; - - // make call - $.ajax({ - type: "GET", - url: call_url, - headers: { - // "Access-Control-Allow-Origin":"*" - "more" : true, - }, - dataType: 'json', - //contentType: 'text/plain;charset=UTF-8', - crossDomain: true, - //async: false, - success: function(result) { - if (result != null && result.hits.length > 0) { - console.log(result); - handleRecipeAPICall(result.hits); - } else { - alert("Your search query returned no results . . . ") - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - console.log("Status: " + textStatus); - console.log("Error: " + errorThrown); - } - }); -} - -function handleRecipeAPICall(recipe_list) { - - // reset recipe list - recipes = {}; - - // iterate through - for (var i = 0; i < recipe_list.length; i++) { - - // get current recipe and id - var current_recipe = recipe_list[i].recipe; - var id = "recipe_" + (i + 1); - - // put in recipe list - recipes[id] = current_recipe; - - // add html - $('#recipe_grid').append( - '
    ' + - '' + - '
    ' + - '

    ' + current_recipe.label + '

    ' + - '
    ' + current_recipe.source + '
    ' + - 'Go to recipe' + - '' - ); - - // on click to show modal - $('#' + id).on('click', function() { - var new_id = this.getAttribute('id'); - // alter html in modal - setAndShowRecipeModal(recipes[new_id]); - }); - } -} - -/******************** - * MODAL FUNCTIONS * - * ******************/ - -function setAndShowFarmModal(farm) { - - // set modal header html - $('#modal_header').html('

    ' + farm.name + '

    '); - - // set modal tab 1 html - $('#tab_1_title').html('Home'); - $('#tab_1').html( - '

    HOME

    ' + - '

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    ' - ); - - // set modal tab 2 html - $('#tab_2_title').html('Contact'); - $('#tab_2').html( - '

    ' + farm.address + '

    ' + - '

    ' + farm.phone + '

    ' + - '
    ' + - ' Visit our webpage | ' + - 'Facebook | ' + - 'Twitter' + - '
    ' - ); - - // set modal tab 3 html - $('#tab_3_title').html('Menu 3'); - $('#tab_3').html( - '

    MENU2

    ' + - '

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    ' - ); - - // set modal tab 4 html - $('#tab_4_title').html('Menu 4'); - $('#tab_4').html( - '

    MENU3

    ' + - '

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    ' - ); - - // show button - $('#contact_button').show(); - $('#recipe_link_button').hide(); - - // show modal - $("#generic_modal").modal() -} - -function setAndShowRecipeModal(recipe) { - - // set modal header html - $('#modal_header').html( - '

    ' + recipe.label + '

    ' + - '

    ' + recipe.source + '

    ' - ); - - // compile tab 1 data - var ingredient_list = '
      '; - for(var i = 0; i < recipe.ingredients.length; i++) { - ingredient_list += "
    • " + recipe.ingredients[i].text + "
    • "; - } - ingredient_list += "
    "; - - // compile tab 2 data - var health_list = '
      '; - for(var i = 0; i < recipe.digest.length; i++) { - health_list += "
    • " - + recipe.digest[i].label - + '' - + Math.round(recipe.digest[i].total * 10) / 10 - + recipe.digest[i].unit - + "
    • "; - } - health_list += "
    "; - - // compile tab 3 data - var nutrient_list = '
      '; - for(var key in recipe.totalDaily) { - //if (!recipe.totalDaily.hasOwnProperty(key)) continue; - - nutrient_list += '
    • ' - + recipe.totalDaily[key].label - + '' - + Math.round(recipe.totalNutrients[key].quantity * 10) / 10 - + recipe.totalNutrients[key].unit + ' (' - + Math.round(recipe.totalDaily[key].quantity * 10) / 10 - + recipe.totalDaily[key].unit - + ")
    • "; - } - nutrient_list += "
    "; - // compile tab 4 data - - // set all modal tabs html content - $('#tab_1_title').html('Ingredients'); - $('#tab_1').html(ingredient_list); - $('#tab_2_title').html('Health Information'); - $('#tab_2').html(health_list); - $('#tab_3_title').html("Nutrients"); - $('#tab_3').html(nutrient_list); - - // hide button - $('#contact_button').hide(); - $('#recipe_link_button').show(); - $('#recipe_link_tag').attr("href", recipe.url); - - - // show modal - $("#generic_modal").modal() -} diff --git a/lfc_development.sqlite3 b/lfc_development.sqlite3 new file mode 100644 index 0000000..0604fe8 Binary files /dev/null and b/lfc_development.sqlite3 differ diff --git a/lfc_test.sqlite3 b/lfc_test.sqlite3 new file mode 100644 index 0000000..6124f25 Binary files /dev/null and b/lfc_test.sqlite3 differ diff --git a/spec/features/farm_edit_page_feature_spec.rb b/spec/features/farm_edit_page_feature_spec.rb new file mode 100644 index 0000000..f05a621 --- /dev/null +++ b/spec/features/farm_edit_page_feature_spec.rb @@ -0,0 +1,157 @@ +require 'rails_helper' + +RSpec.feature "Farm edit page can be reached", :type => :feature do + before (:each) do + f = Farm.create!(name: "Test2", + address: "123 St", + password: "123456", + phone: 3140614241, + facebook: "facebook.com/test2", + twitter: "twitter/farm2", + created_at: "2018-011-18 20:45:00", + updated_at: nil, + approved: false, + original_id: 1, + email: "test2@example.com", + contact_name: "Barb", + year: 2018, + statement: "I like farming", + other_media: nil, + link_to_cert: nil, + growth_promoter: false, + antibiotic: false, + fav_activity: "", + primary_operation_id: 2) + + @id = f.id + end + scenario "when a farm is created" do + visit "/farms/#{@id}/edit" + end + + scenario "An unlogged in user clicks on the edit link" do + #Get the login page + #Check the login authentication + #Redirect to the farm's edit page + #Assert that we are on the edit page + end + + scenario "A logged in user goes to the edit page" do + #Assert that the user is logged in + #Redirect to the user's farm's edit page + #Assert that we are on the correct page + end + + scenario "An unlogged in user attempts to access the edit page directly" do + #Get the farm's edit page + #Assert that an error is raised denying access + end + +end + +RSpec.feature "A valid user attempts to edit their farm by", :type => :feature do + before (:each) do + f = Farm.create!(name: "Test2", + address: "123 St", + password: "123456", + phone: 3140614241, + facebook: "facebook.com/test2", + twitter: "twitter/farm2", + created_at: "2018-011-18 20:45:00", + updated_at: nil, + approved: false, + original_id: 1, + email: "test2@example.com", + contact_name: "Barb", + year: 2018, + statement: "I like farming", + other_media: nil, + link_to_cert: nil, + growth_promoter: false, + antibiotic: false, + fav_activity: "", + primary_operation_id: 2) + + @id = f.id + #Get the login page + #Enter the login creds for Test2 + #Get the edit page for f.id + + + end + scenario "Updating the farm's name" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's password" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's email" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's primary contact name" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's URL" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's telephone number" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's facebook" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's instagram" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's twitter" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's market" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's growing methods" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's selling methods" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's operations" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's statement" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end + scenario "Updating the farm's media" do + #Fill in field with new data + #Click submit + #Expect that the farm's field is now updated + end +end \ No newline at end of file diff --git a/spec/features/farm_signup_page_feature_spec.rb b/spec/features/farm_signup_page_feature_spec.rb new file mode 100644 index 0000000..a850531 --- /dev/null +++ b/spec/features/farm_signup_page_feature_spec.rb @@ -0,0 +1,64 @@ +require 'rails_helper' + +RSpec.feature "Farm signup exsists when", :type => :feature do + scenario "User goes directly to signup page" do + visit '/signup' + # expect(page).to be '/farms/new' + end + scenario "User clicks the signup link from home page" do + visit "/" + click_link "Sign up" + expect(page.current_path).to eq(new_farm_path) + end + +end + + + +RSpec.feature "Farmer tries to sign up", :type => :feature do + #Testing the form found in /views/farms/new.html.erb + + before (:each) do + visit '/farms/new' + + fill_in "Name", :with => "Test Farm" + fill_in "Address", :with => "1115 8th Ave Grinnell, IA 50112" + fill_in "Url", :with => "example.com" + fill_in "Phone", :with => "123-456-7890" + fill_in "Facebook", :with => "testFarm" + fill_in "Instagram", :with => "testFarm" + fill_in "Twitter", :with => "@testFarm" + end + + scenario " with valid input" do + + fill_in "Email", :with => "testfarm@example.com" + fill_in "Password", :with => "1234567890" + + find('[for=farm_operations_2]').click + #check :id =>'farm_operations_1' + + click_button "Submit" + + expect(Farms.count).to eq(1) + #response.should redirect_to '/submission' #Not yet working on the farms/new + end + + scenario "with an invalid email" do + fill_in "Email", :with => "123example.com" #an invalid email + fill_in "Password", :with => "1234567890" + expect {click_button "Submit"}.to raise_error + + + #Figure out what we want to have it do when this scenario arises + end + + scenario "with an invalid password" do + fill_in "Email", :with => "testfarm@example.com" + fill_in "Password", :with => "123" + + expect {click_button "Submit"}.to raise_error + + #Figure out what we want to have it do when this scenario arises + end +end \ No newline at end of file diff --git a/spec/features/footer_feature_spec.rb b/spec/features/footer_feature_spec.rb new file mode 100644 index 0000000..3b34647 --- /dev/null +++ b/spec/features/footer_feature_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +RSpec.feature "Footer Features", :type => :feature do + before (:each) do + visit root_path + end + + context "footer elements are present" do + scenario "should contain the site's email" do + expect(page).to have_content("info@localfoodsconnection.com") + end + + scenario "should contain the phone number" do + expect(page).to have_content("(641) 990-0018") + end + + scenario "should contain the instagram link" do + expect(page).to have_selector(:css, 'a[href="https://www.instagram.com/localfoodsconnection/"]') + end + + scenario "should contain a link to the site's email" do + expect(page).to have_selector(:css, 'a[href="mailto:info@localfoodsconnection.com"]') + end + + scenario "should contain the facebook link" do + expect(page).to have_selector(:css, 'a[href="https://www.facebook.com/LocalFoodsConnection/"]') + end + end +end diff --git a/spec/features/header_feature_spec.rb b/spec/features/header_feature_spec.rb new file mode 100644 index 0000000..81d6fa5 --- /dev/null +++ b/spec/features/header_feature_spec.rb @@ -0,0 +1,56 @@ +require 'rails_helper' + +RSpec.feature "Header Features", :type => :feature do + before (:each) do + visit root_path + end + + context "header elements are present" do + scenario "should contain the logo" do + expect(page).to have_css("img[src*='logo.png']") + end + + scenario "should contain the home tab" do + expect(page).to have_content("Home") + end + + scenario "should contain the map tab" do + expect(page).to have_content("Map") + end + + scenario "should contain the signup tab" do + expect(page).to have_content("Sign up") + end + + scenario "should contain the signin tab" do + expect(page).to have_content("Sign In") + end + end + + context "header responds as expected" do + scenario "clicking the LFC logo should redirect to the LFC website" do + #click on the logo + #assert that it redirects to the proper place + end + + scenario "clicking the home tab should redirect to root_path" do + click_link("Home") + expect(page.current_path).to eq(root_path) + end + + scenario "clicking the map tab should redirect to the map page" do + click_link("Map") + expect(page.current_path).to eq(map_path) + end + + scenario "clicking the signup tab should redirect to signup page" do + click_link("Sign up") + expect(page.current_path).to eq(new_farm_path) + end + + scenario "clicking the the signin tab redirects to signin page" do + click_link("Sign In") + expect(page.current_path).to eq('/signin') + end + end +end diff --git a/spec/features/home_page_feature_spec.rb b/spec/features/home_page_feature_spec.rb new file mode 100644 index 0000000..a4a0c69 --- /dev/null +++ b/spec/features/home_page_feature_spec.rb @@ -0,0 +1,58 @@ +require 'rails_helper' + +RSpec.feature "Home Page Features", :type => :feature do + before (:each) do + visit root_path + end + + context "home page elements are present" do + scenario "should contain the header" do + expect(page).to have_css('header') + end + + scenario "should contain the search bar" do + expect(page).to have_css('div.search-bar') + #possibly not the best way to test that the search bar exists + end + + scenario "should contain the card grid" do + expect(page).to have_css ('div.card-grid') + end + + scenario "should contain the hero"do + expect(page).to have_css('div.hero') + end + + scenario "should contain the correct hero text" do + expect(page).to have_content("Search Local Farms") + end + + scenario "should contain the footer" do + expect(page).to have_css('footer') + end + end + + context "the home page responds as expected" do + scenario "the search bar should filter the cards" do + #Create a CSA Farm + f = Farm.create!(name: "Compass Plant CSA", + address: "2039 N. Penrose Street. Grinnell, IA 50112", + phone: '641-990-6832', + email: 'ladunham@wildblue.net', + password: 'password' + ) + #fill in some stuff + fill_in "search-text-home" , :with => "CSA" + #assert that it's what we want + within(:css, 'div.card-grid') do + #expect(page).to have_css('div#farm_6') + expect(page).to have_content('Compass Plant CSA') + end + end + + scenario "clicking on a card should link to the farmer's page" do + #click on a card + #assert that it redirects to the proper path + end + end +end diff --git a/spec/models/farm_spec.rb b/spec/models/farm_spec.rb new file mode 100644 index 0000000..10bc2ae --- /dev/null +++ b/spec/models/farm_spec.rb @@ -0,0 +1,92 @@ +require 'rails_helper' + +RSpec.describe Farm, type: :model do + before :each do + farm_params = {name: "Test", + address: "123 St", + password: "123456", + phone: 123456, + email: "test@example.com"} + @testFarm = Farm.create!(farm_params) + end + + describe "new" do + it "should return a farm object" do + expect(@testFarm).to be_an_instance_of Farm + end + end + + describe "admin" do + it "should return true for admin" do + @testFarm.role = :admin + expect(@testFarm.admin?).to eql true + end + end + + describe "default_role" do + it "should set the default role" do + @testFarm.set_default_role + expect(@testFarm.role).to eql "farm" + end + end + + describe "operations" do + before :each do + @testFarm.operations << Operation.new(food: "test", id: 1) + @testFarm.reload + end + + it "should hold on to operations when I save them" do + expect(@testFarm.operations.count).to eql 1 + end + + it "should save the right operation" do + expect(@testFarm.operations.find(1).food).to eql "test" + end + end + + describe "growing methods" do + before :each do + @testFarm.growing_methods << GrowingMethod.new(grow_method: "Test", id: 1) + @testFarm.reload + end + + it "should hold on to growing methods when I save them" do + expect(@testFarm.growing_methods.count).to eql 1 + end + + it "should save the right growing method" do + expect(@testFarm.growing_methods.find(1).grow_method).to eql "Test" + end + end + + describe "selling methods" do + before :each do + @testFarm.selling_methods << SellingMethod.new(sell_method: "Test", id: 1) + @testFarm.reload + end + + it "should hold on to selling methods when I save them" do + expect(@testFarm.selling_methods.count).to eql 1 + end + + it "should save the right selling method" do + expect(@testFarm.selling_methods.find(1).sell_method).to eql "Test" + end + end + + describe "markets" do + before :each do + @testFarm.markets << Market.new(location: "Test", id: 1) + @testFarm.reload + end + + it "should hold on to markets when I save them" do + expect(@testFarm.markets.count).to eql 1 + end + + it "should save the right market" do + expect(@testFarm.markets.find(1).location).to eql "Test" + end + end +end diff --git a/spec/models/growing_method_spec.rb b/spec/models/growing_method_spec.rb new file mode 100644 index 0000000..128e8f2 --- /dev/null +++ b/spec/models/growing_method_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.describe GrowingMethod, type: :model do + before :each do + growing_method_params = {grow_method: "Test"} + @testGrowingMethod = GrowingMethod.create!(growing_method_params) + end + + describe "new" do + it "should return a growing_method object" do + expect(@testGrowingMethod).to be_an_instance_of GrowingMethod + end + end + + describe "display_name" do + it "should display the right growing_method name" do + expect(@testGrowingMethod.display_name).to eql "Test" + end + end + + describe "farms" do + before :each do + @testGrowingMethod.farms << Farm.new(name: "Test", + password: "123456", + email: "test@example.com", + id: 1) + @testGrowingMethod.reload + end + + it "should hold on to farms when I save them" do + expect(@testGrowingMethod.farms.count).to eql 1 + end + + it "should save the right farm" do + expect(@testGrowingMethod.farms.find(1).name).to eql "Test" + end + end +end diff --git a/spec/models/market_spec.rb b/spec/models/market_spec.rb new file mode 100644 index 0000000..feae647 --- /dev/null +++ b/spec/models/market_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.describe Market, type: :model do + before :each do + market_params = {location: "Test"} + @testMarket = Market.create!(market_params) + end + + describe "new" do + it "should return a market object" do + expect(@testMarket).to be_an_instance_of Market + end + end + + describe "display_name" do + it "should display the right market name" do + expect(@testMarket.display_name).to eql "Test" + end + end + + describe "farms" do + before :each do + @testMarket.farms << Farm.new(name: "Test", + password: "123456", + email: "test@example.com", + id: 1) + @testMarket.reload + end + + it "should hold on to farms when I save them" do + expect(@testMarket.farms.count).to eql 1 + end + + it "should save the right farm" do + expect(@testMarket.farms.find(1).name).to eql "Test" + end + end +end diff --git a/spec/models/operation_spec.rb b/spec/models/operation_spec.rb new file mode 100644 index 0000000..e75f30a --- /dev/null +++ b/spec/models/operation_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.describe Operation, type: :model do + before :each do + operation_params = {food: "test"} + @testOperation = Operation.create!(operation_params) + end + + describe "new" do + it "should return an operation object" do + expect(@testOperation).to be_an_instance_of Operation + end + end + + describe "display_name" do + it "should display the right operation name" do + expect(@testOperation.display_name).to eql "test" + end + end + + describe "farms" do + before :each do + @testOperation.farms << Farm.new(name: "Test", + password: "123456", + email: "test@example.com", + id: 1) + @testOperation.reload + end + + it "should hold on to farms when I save them" do + expect(@testOperation.farms.count).to eql 1 + end + + it "should save the right farm" do + expect(@testOperation.farms.find(1).name).to eql "Test" + end + end +end diff --git a/spec/models/primary_operation_spec.rb b/spec/models/primary_operation_spec.rb new file mode 100644 index 0000000..ebf3db8 --- /dev/null +++ b/spec/models/primary_operation_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe PrimaryOperation, type: :model do + before :each do + primary_operation_params = {food: "test"} + @testPrimaryOperation = PrimaryOperation.create!(primary_operation_params) + end + + describe "new" do + it "should return a primary operation object" do + expect(@testPrimaryOperation).to be_an_instance_of PrimaryOperation + end + end + + describe "display_name" do + it "should display the right primary operation name" do + expect(@testPrimaryOperation.display_name).to eql "test" + end + end +end diff --git a/spec/models/selling_method_spec.rb b/spec/models/selling_method_spec.rb new file mode 100644 index 0000000..0eb9f61 --- /dev/null +++ b/spec/models/selling_method_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.describe SellingMethod, type: :model do + before :each do + selling_method_params = {sell_method: "Test"} + @testSellingMethod = SellingMethod.create!(selling_method_params) + end + + describe "new" do + it "should return a selling_method object" do + expect(@testSellingMethod).to be_an_instance_of SellingMethod + end + end + + describe "display_name" do + it "should display the right selling_method name" do + expect(@testSellingMethod.display_name).to eql "Test" + end + end + + describe "farms" do + before :each do + @testSellingMethod.farms << Farm.new(name: "Test", + password: "123456", + email: "test@example.com", + id: 1) + @testSellingMethod.reload + end + + it "should hold on to farms when I save them" do + expect(@testSellingMethod.farms.count).to eql 1 + end + + it "should save the right farm" do + expect(@testSellingMethod.farms.find(1).name).to eql "Test" + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..d73d80b --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,61 @@ +# 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' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..4572959 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,97 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end +require 'capybara/rspec' \ No newline at end of file diff --git a/test/controllers/static_pages_controller_test.rb b/test/controllers/static_pages_controller_test.rb new file mode 100644 index 0000000..284a47b --- /dev/null +++ b/test/controllers/static_pages_controller_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class StaticPagesControllerTest < ActionDispatch::IntegrationTest + + def setup + @base_title = "Local Foods Connection" + end + + + test "should get home" do + get static_pages_home_url + assert_response :success + assert_select "title", "Home | #{@base_title}" + end + + test "should get map" do + get static_pages_map_url + assert_response :success + assert_select "title", "Map | #{@base_title}" + end + +end diff --git a/test/decorators/ui_decorator_test.rb b/test/decorators/ui_decorator_test.rb new file mode 100644 index 0000000..5d71bea --- /dev/null +++ b/test/decorators/ui_decorator_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UiDecoratorTest < Draper::TestCase +end diff --git a/test/fixtures/farms_operations.yml b/test/fixtures/farms_operations.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/farms_operations.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/primary_operations.yml b/test/fixtures/primary_operations.yml new file mode 100644 index 0000000..87b1ade --- /dev/null +++ b/test/fixtures/primary_operations.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + food: MyString + +two: + food: MyString diff --git a/test/models/farm_test.rb b/test/models/farm_test.rb index 40b0e54..161fb73 100644 --- a/test/models/farm_test.rb +++ b/test/models/farm_test.rb @@ -1,7 +1,12 @@ require 'test_helper' + class FarmTest < ActiveSupport::TestCase # test "the truth" do # assert true - # end + # end + test "should create a new farm in the database" do + testFarm = Farm.create!(name: "Test2", address: "123 St",password: "123456", phone: 3140614241, facebook: "facebook.com/test2", twitter: "twitter/farm2", created_at: "2018-011-18 20:45:00", updated_at: nil, approved: false, original_id: 1, email: "test2@gmal.com", contact_name: "Barb", year: 2018, statement: "She is your rich old granny", other_media: nil, link_to_cert: nil, growth_promoter: false, antibiotic: false,fav_activity: "", primary_operation_id: 2) + assert Farm.last.to eq(testFarm) + end end diff --git a/test/models/farms_operation_test.rb b/test/models/farms_operation_test.rb new file mode 100644 index 0000000..332be27 --- /dev/null +++ b/test/models/farms_operation_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class FarmsOperationTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/primary_operation_test.rb b/test/models/primary_operation_test.rb new file mode 100644 index 0000000..01be4c7 --- /dev/null +++ b/test/models/primary_operation_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PrimaryOperationTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end