From 053f035d31216c775d3cc1895b26d3e367dc5319 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 12 Oct 2015 11:22:55 +0800 Subject: [PATCH 01/44] move fixtures to seeds.rb --- db/seeds.rb | 304 +++++++++++++++++++++++++++++ test/fixtures/.gitkeep | 0 test/fixtures/in_metacode_sets.yml | 9 - test/fixtures/mappings.yml | 11 -- test/fixtures/metacode_sets.yml | 13 -- test/fixtures/metacodes.yml | 240 ----------------------- test/fixtures/topics.yml | 11 -- test/fixtures/users.yml | 17 -- 8 files changed, 304 insertions(+), 301 deletions(-) delete mode 100644 test/fixtures/.gitkeep delete mode 100644 test/fixtures/in_metacode_sets.yml delete mode 100644 test/fixtures/mappings.yml delete mode 100644 test/fixtures/metacode_sets.yml delete mode 100644 test/fixtures/metacodes.yml delete mode 100644 test/fixtures/topics.yml delete mode 100644 test/fixtures/users.yml diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e85..b6bbd9ca 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,307 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +## USERS + +User.create({ + name: 'user', + email: 'user@user.com', + password: 'toolsplusconsciousness', + code: 'qwertyui', + joinedwithcode: 'qwertyui', + admin: 'false', +}) + +User.create({ + name: 'admin', + email: 'admin@admin.com', + password: 'toolsplusconsciousness', + code: 'iuytrewq', + joinedwithcode: 'iuytrewq', + admin: 'true', +}) + +## METACODES +Metacode.create({ + name: 'Action', + icon: '/assets/icons/blueprint_96px/bp_action.png', + color: '#BD6C85', +}) + +Metacode.create({ + name: 'Activity', + icon: '/assets/icons/blueprint_96px/bp_activity.png', + color: '#6EBF65', +}) + +Metacode.create({ + name: 'Catalyst', + icon: '/assets/icons/blueprint_96px/bp_catalyst.png', + color: '#EF8964', +}) + +Metacode.create({ + name: 'Closed', + icon: '/assets/icons/blueprint_96px/bp_closedissue.png', + color: '#ABB49F', +}) + +Metacode.create({ + name: 'Process', + icon: '/assets/icons/blueprint_96px/bp_process.png', + color: '#BDB25E', +}) + +Metacode.create({ + name: 'Future Dev', + icon: '/assets/icons/blueprint_96px/bp_futuredev.png', + color: '#25A17F', +}) + +Metacode.create({ + name: 'Group', + icon: '/assets/icons/blueprint_96px/bp_group.png', + color: '#7076BC', +}) + +Metacode.create({ + name: 'Implication', + icon: '/assets/icons/blueprint_96px/bp_implication.png', + color: '#83DECA', +}) + +Metacode.create({ + name: 'Insight', + icon: '/assets/icons/blueprint_96px/bp_insight.png', + color: '#B074AD', +}) + +Metacode.create({ + name: 'Intention', + icon: '/assets/icons/blueprint_96px/bp_intention.png', + color: '#BAEAFF', +}) + +Metacode.create({ + name: 'Knowledge', + icon: '/assets/icons/blueprint_96px/bp_knowledge.png', + color: '#60ACF7', +}) + +Metacode.create({ + name: 'Location', + icon: '/assets/icons/blueprint_96px/bp_location.png', + color: '#ABD9A7', +}) + +Metacode.create({ + name: 'Need ', + icon: '/assets/icons/blueprint_96px/bp_need.png', + color: '#D2A7D4', +}) + +Metacode.create({ + name: 'Open Issue', + icon: '/assets/icons/blueprint_96px/bp_openissue.png', + color: '#9BBF71', +}) + +Metacode.create({ + name: 'Opportunity', + icon: '/assets/icons/blueprint_96px/bp_opportunity.png', + color: '#889F64', +}) + +Metacode.create({ + name: 'Person', + icon: '/assets/icons/blueprint_96px/bp_person.png', + color: '#DE925F', +}) + +Metacode.create({ + name: 'Platform', + icon: '/assets/icons/blueprint_96px/bp_platform.png', + color: '#21C8FE', +}) + +Metacode.create({ + name: 'Problem', + icon: '/assets/icons/blueprint_96px/bp_problem.png', + color: '#99CFC4', +}) + +Metacode.create({ + name: 'Resource', + icon: '/assets/icons/blueprint_96px/bp_resource.png', + color: '#C98C63 ', +}) + +Metacode.create({ + name: 'Role', + icon: '/assets/icons/blueprint_96px/bp_role.png', + color: '#A8595D', +}) + +Metacode.create({ + name: 'Task', + icon: '/assets/icons/blueprint_96px/bp_task.png', + color: '#3397C4', +}) + +Metacode.create({ + name: 'Trajectory', + icon: '/assets/icons/blueprint_96px/bp_trajectory.png', + color: '#D3AA4C', +}) + +Metacode.create({ + name: 'Argument', + icon: '/assets/icons/generics_96px/gen_argument.png', + color: '#7FAEFD', +}) + +Metacode.create({ + name: 'Con', + icon: '/assets/icons/generics_96px/gen_con.png', + color: '#CF7C74', +}) + +Metacode.create({ + name: 'Subject', + icon: '/assets/icons/generics_96px/gen_subject.png', + color: '#8293D8', +}) + +Metacode.create({ + name: 'Decision', + icon: '/assets/icons/generics_96px/gen_decision.png', + color: '#CCA866', +}) + +Metacode.create({ + name: 'Event ', + icon: '/assets/icons/generics_96px/gen_event.png', + color: '#F5854B', +}) + +Metacode.create({ + name: 'Example', + icon: '/assets/icons/generics_96px/gen_example.png', + color: '#618C61', +}) + +Metacode.create({ + name: 'Experience', + icon: '/assets/icons/generics_96px/gen_experience.png', + color: '#BE995F', +}) + +Metacode.create({ + name: 'Feedback', + icon: '/assets/icons/generics_96px/gen_feedback.png', + color: '#54A19D', +}) + +Metacode.create({ + name: 'Aim', + icon: '/assets/icons/generics_96px/gen_aim.png', + color: '#B0B0B0', +}) + +Metacode.create({ + name: 'Good Practice', + icon: '/assets/icons/generics_96px/gen_goodpractice.png', + color: '#BD9E86', +}) + +Metacode.create({ + name: 'Idea', + icon: '/assets/icons/generics_96px/gen_idea.png', + color: '#C4BC5E', +}) + +Metacode.create({ + name: 'List', + icon: '/assets/icons/generics_96px/gen_list.png', + color: '#B7A499', +}) + +Metacode.create({ + name: 'Media', + icon: '/assets/icons/generics_96px/gen_media.png', + color: '#6D94CC', +}) + +Metacode.create({ + name: 'Metamap', + icon: '/assets/icons/generics_96px/gen_metamap.png', + color: '#AEA9FD', +}) + +Metacode.create({ + name: 'Model', + icon: '/assets/icons/generics_96px/gen_model.png', + color: '#B385BA', +}) + +Metacode.create({ + name: 'Note', + icon: '/assets/icons/generics_96px/gen_note.png', + color: '#A389A1', +}) + +Metacode.create({ + name: 'Perspective', + icon: '/assets/icons/generics_96px/gen_perspective.png', + color: '#2EB6CC', +}) + +Metacode.create({ + name: 'Pro', + icon: '/assets/icons/generics_96px/gen_pro.png', + color: '#89B879', +}) + +Metacode.create({ + name: 'Project', + icon: '/assets/icons/generics_96px/gen_project.png', + color: '#85A050', +}) + +Metacode.create({ + name: 'Question', + icon: '/assets/icons/generics_96px/gen_question.png', + color: '#5CB3B3', +}) + +Metacode.create({ + name: 'Reference', + icon: '/assets/icons/generics_96px/gen_reference.png', + color: '#A7A7A7', +}) + +Metacode.create({ + name: 'Research', + icon: '/assets/icons/generics_96px/gen_research.png', + color: '#CD8E89', +}) + +Metacode.create({ + name: 'Status update', + icon: '/assets/icons/generics_96px/gen_status.png', + color: '#EFA7C0', +}) + +Metacode.create({ + name: 'Tool', + icon: '/assets/icons/generics_96px/gen_tool.png ', + color: '#828282', +}) + +Metacode.create({ + name: 'Wildcard', + icon: '/assets/icons/generics_96px/gen_wildcard.png', + color: '#73C7DE', +}) diff --git a/test/fixtures/.gitkeep b/test/fixtures/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/in_metacode_sets.yml b/test/fixtures/in_metacode_sets.yml deleted file mode 100644 index 9879c73b..00000000 --- a/test/fixtures/in_metacode_sets.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -#one: -# metacode: -# metacode_set: - -#two: -# metacode: -# metacode_set: diff --git a/test/fixtures/mappings.yml b/test/fixtures/mappings.yml deleted file mode 100644 index 9cfe87b6..00000000 --- a/test/fixtures/mappings.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.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/metacode_sets.yml b/test/fixtures/metacode_sets.yml deleted file mode 100644 index 56bda62e..00000000 --- a/test/fixtures/metacode_sets.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -#one: -# name: MyString -# desc: MyText -# user: -# mapperContributed: false - -#two: -# name: MyString -# desc: MyText -# user: -# mapperContributed: false diff --git a/test/fixtures/metacodes.yml b/test/fixtures/metacodes.yml deleted file mode 100644 index 02ec0663..00000000 --- a/test/fixtures/metacodes.yml +++ /dev/null @@ -1,240 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.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: - name: Action - icon: /assets/icons/blueprint_96px/bp_action.png - color: #BD6C85 - -two: - name: Activity - icon: /assets/icons/blueprint_96px/bp_activity.png - color: #6EBF65 - -three: - name: Catalyst - icon: /assets/icons/blueprint_96px/bp_catalyst.png - color: #EF8964 - -four: - name: Closed - icon: /assets/icons/blueprint_96px/bp_closedissue.png - color: #ABB49F - -five: - name: Process - icon: /assets/icons/blueprint_96px/bp_process.png - color: #BDB25E - -six: - name: Future Dev - icon: /assets/icons/blueprint_96px/bp_futuredev.png - color: #25A17F - -seven: - name: Group - icon: /assets/icons/blueprint_96px/bp_group.png - color: #7076BC - -eight: - name: Implication - icon: /assets/icons/blueprint_96px/bp_implication.png - color: #83DECA - -nine: - name: Insight - icon: /assets/icons/blueprint_96px/bp_insight.png - color: #B074AD - -ten: - name: Intention - icon: /assets/icons/blueprint_96px/bp_intention.png - color: #BAEAFF - -eleven: - name: Knowledge - icon: /assets/icons/blueprint_96px/bp_knowledge.png - color: #60ACF7 - -twelve: - name: Location - icon: /assets/icons/blueprint_96px/bp_location.png - color: #ABD9A7 - -thirteen: - name: Need - icon: /assets/icons/blueprint_96px/bp_need.png - color: #D2A7D4 - -fourteen: - name: Open Issue - icon: /assets/icons/blueprint_96px/bp_openissue.png - color: #9BBF71 - -fifteen: - name: Opportunity - icon: /assets/icons/blueprint_96px/bp_opportunity.png - color: #889F64 - -sixteen: - name: Person - icon: /assets/icons/blueprint_96px/bp_person.png - color: #DE925F - -seventeen: - name: Platform - icon: /assets/icons/blueprint_96px/bp_platform.png - color: #21C8FE - -eighteen: - name: Problem - icon: /assets/icons/blueprint_96px/bp_problem.png - color: #99CFC4 - -nineteen: - name: Resource - icon: /assets/icons/blueprint_96px/bp_resource.png - color: #C98C63 - -twenty: - name: Role - icon: /assets/icons/blueprint_96px/bp_role.png - color: #A8595D - -twenty-one: - name: Task - icon: /assets/icons/blueprint_96px/bp_task.png - color: #3397C4 - -twenty-two: - name: Trajectory - icon: /assets/icons/blueprint_96px/bp_trajectory.png - color: #D3AA4C - -twenty-three: - name: Argument - icon: /assets/icons/generics_96px/gen_argument.png - color: #7FAEFD - -twenty-four: - name: Con - icon: /assets/icons/generics_96px/gen_con.png - color: #CF7C74 - -twenty-five: - name: Subject - icon: /assets/icons/generics_96px/gen_subject.png - color: #8293D8 - -twenty-six: - name: Decision - icon: /assets/icons/generics_96px/gen_decision.png - color: #CCA866 - -twenty-seven: - name: Event - icon: /assets/icons/generics_96px/gen_event.png - color: #F5854B - -twenty-eight: - name: Example - icon: /assets/icons/generics_96px/gen_example.png - color: #618C61 - -twenty-nine: - name: Experience - icon: /assets/icons/generics_96px/gen_experience.png - color: #BE995F - -thirty: - name: Feedback - icon: /assets/icons/generics_96px/gen_feedback.png - color: #54A19D - -thirty-one: - name: Aim - icon: /assets/icons/generics_96px/gen_aim.png - color: #B0B0B0 - -thirty-two: - name: Good Practice - icon: /assets/icons/generics_96px/gen_goodpractice.png - color: #BD9E86 - -thirty-three: - name: Idea - icon: /assets/icons/generics_96px/gen_idea.png - color: #C4BC5E - -thirty-four: - name: List - icon: /assets/icons/generics_96px/gen_list.png - color: #B7A499 - -thirty-five: - name: Media - icon: /assets/icons/generics_96px/gen_media.png - color: #6D94CC - -thirty-six: - name: Metamap - icon: /assets/icons/generics_96px/gen_metamap.png - color: #AEA9FD - -thirty-seven: - name: Model - icon: /assets/icons/generics_96px/gen_model.png - color: #B385BA - -thirty-eight: - name: Note - icon: /assets/icons/generics_96px/gen_note.png - color: #A389A1 - -thirty-nine: - name: Perspective - icon: /assets/icons/generics_96px/gen_perspective.png - color: #2EB6CC - -forty: - name: Pro - icon: /assets/icons/generics_96px/gen_pro.png - color: #89B879 - -forty-one: - name: Project - icon: /assets/icons/generics_96px/gen_project.png - color: #85A050 - -forty-two: - name: Question - icon: /assets/icons/generics_96px/gen_question.png - color: #5CB3B3 - -forty-three: - name: Reference - icon: /assets/icons/generics_96px/gen_reference.png - color: #A7A7A7 - -forty-four: - name: Research - icon: /assets/icons/generics_96px/gen_research.png - color: #CD8E89 - -forty-five: - name: Status update - icon: /assets/icons/generics_96px/gen_status.png - color: #EFA7C0 - -forty-six: - name: Tool - icon: /assets/icons/generics_96px/gen_tool.png - color: #828282 - -forty-seven: - name: Wildcard - icon: /assets/icons/generics_96px/gen_wildcard.png - color: #73C7DE diff --git a/test/fixtures/topics.yml b/test/fixtures/topics.yml deleted file mode 100644 index 9cfe87b6..00000000 --- a/test/fixtures/topics.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.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/users.yml b/test/fixtures/users.yml deleted file mode 100644 index 8a461a50..00000000 --- a/test/fixtures/users.yml +++ /dev/null @@ -1,17 +0,0 @@ -#password: toolsplusconsciousness - -user: - name: user - email: user@user.com - encrypted_password: $2a$10$psR68SWYNy5ZKQPs9FrFM.HuRMrTXO/YFzv.HaUmdCsQZsQrG1XAW - code: qwertyui - joinedwithcode: qwertyui - admin: false - -admin: - name: admin - email: admin@admin.com - encrypted_password: $2a$10$psR68SWYNy5ZKQPs9FrFM.HuRMrTXO/YFzv.HaUmdCsQZsQrG1XAW - code: iuytrewq - joinedwithcode: iuytrewq - admin: true From 0d2ddbd9b6be6d5a384d655f02cef73fa8d3e00b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 12 Oct 2015 11:24:30 +0800 Subject: [PATCH 02/44] add rspec to Gemfile --- Gemfile | 5 +++++ Gemfile.lock | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Gemfile b/Gemfile index 9489f21d..4732f0a8 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,11 @@ group :assets do gem 'uglifier', '>= 1.0.3' end +group :test do + gem 'rspec-rails' + gem 'factory_girl_rails' +end + group :production do #this is used on heroku #gem 'rmagick' end diff --git a/Gemfile.lock b/Gemfile.lock index 98a5e233..5b431d4e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,10 +59,16 @@ GEM responders thread_safe (~> 0.1) warden (~> 1.2.3) + diff-lcs (1.2.5) dotenv (2.0.0) erubis (2.7.0) execjs (2.2.1) ezcrypto (0.7.2) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) formtastic (3.0.0) actionpack (>= 3.2.13) formula (1.0.1) @@ -129,6 +135,23 @@ GEM redis (3.1.0) responders (1.1.1) railties (>= 3.2, < 4.2) + rspec-core (3.3.1) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-rails (3.3.2) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) sass (3.4.5) sass-rails (3.2.6) railties (~> 3.2.0) @@ -167,6 +190,7 @@ DEPENDENCIES coffee-rails (~> 3.2.1) devise dotenv + factory_girl_rails formtastic formula jbuilder (= 0.8.2) @@ -178,6 +202,10 @@ DEPENDENCIES rails (= 3.2.17) rails3-jquery-autocomplete redis + rspec-rails sass-rails uglifier (>= 1.0.3) uservoice-ruby + +BUNDLED WITH + 1.10.6 From 16c47d75d45d4302efa634931f534598e76e10a6 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 12 Oct 2015 11:26:48 +0800 Subject: [PATCH 03/44] delete test directory, add spec directory --- .rspec | 2 + spec/rails_helper.rb | 48 ++++++++++ spec/spec_helper.rb | 92 +++++++++++++++++++ test/functional/.gitkeep | 0 .../in_metacode_sets_controller_test.rb | 49 ---------- test/functional/main_controller_test.rb | 7 -- test/functional/mapping_controller_test.rb | 9 -- test/functional/maps_controller_test.rb | 7 -- .../metacode_sets_controller_test.rb | 49 ---------- test/functional/metacodes_controller_test.rb | 49 ---------- test/functional/sessions_controller_test.rb | 7 -- test/functional/synapses_controller_test.rb | 7 -- test/functional/topics_controller_test.rb | 7 -- test/functional/users_controller_test.rb | 7 -- test/integration/.gitkeep | 0 test/performance/browsing_test.rb | 12 --- test/test_helper.rb | 13 --- test/unit/.gitkeep | 0 .../helpers/in_metacode_sets_helper_test.rb | 4 - test/unit/helpers/main_helper_test.rb | 4 - test/unit/helpers/mapping_helper_test.rb | 4 - test/unit/helpers/maps_helper_test.rb | 4 - .../unit/helpers/metacode_sets_helper_test.rb | 4 - test/unit/helpers/metacodes_helper_test.rb | 4 - test/unit/helpers/sessions_helper_test.rb | 4 - test/unit/helpers/synapses_helper_test.rb | 4 - test/unit/helpers/topics_helper_test.rb | 4 - test/unit/helpers/users_helper_test.rb | 4 - test/unit/in_metacode_set_test.rb | 7 -- test/unit/map_test.rb | 7 -- test/unit/mapping_test.rb | 7 -- test/unit/metacode_set_test.rb | 7 -- test/unit/metacode_test.rb | 7 -- test/unit/session_test.rb | 7 -- test/unit/synapse_test.rb | 7 -- test/unit/topic_test.rb | 7 -- test/unit/user_test.rb | 7 -- 37 files changed, 142 insertions(+), 326 deletions(-) create mode 100644 .rspec create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb delete mode 100644 test/functional/.gitkeep delete mode 100644 test/functional/in_metacode_sets_controller_test.rb delete mode 100644 test/functional/main_controller_test.rb delete mode 100644 test/functional/mapping_controller_test.rb delete mode 100644 test/functional/maps_controller_test.rb delete mode 100644 test/functional/metacode_sets_controller_test.rb delete mode 100644 test/functional/metacodes_controller_test.rb delete mode 100644 test/functional/sessions_controller_test.rb delete mode 100644 test/functional/synapses_controller_test.rb delete mode 100644 test/functional/topics_controller_test.rb delete mode 100644 test/functional/users_controller_test.rb delete mode 100644 test/integration/.gitkeep delete mode 100644 test/performance/browsing_test.rb delete mode 100644 test/test_helper.rb delete mode 100644 test/unit/.gitkeep delete mode 100644 test/unit/helpers/in_metacode_sets_helper_test.rb delete mode 100644 test/unit/helpers/main_helper_test.rb delete mode 100644 test/unit/helpers/mapping_helper_test.rb delete mode 100644 test/unit/helpers/maps_helper_test.rb delete mode 100644 test/unit/helpers/metacode_sets_helper_test.rb delete mode 100644 test/unit/helpers/metacodes_helper_test.rb delete mode 100644 test/unit/helpers/sessions_helper_test.rb delete mode 100644 test/unit/helpers/synapses_helper_test.rb delete mode 100644 test/unit/helpers/topics_helper_test.rb delete mode 100644 test/unit/helpers/users_helper_test.rb delete mode 100644 test/unit/in_metacode_set_test.rb delete mode 100644 test/unit/map_test.rb delete mode 100644 test/unit/mapping_test.rb delete mode 100644 test/unit/metacode_set_test.rb delete mode 100644 test/unit/metacode_test.rb delete mode 100644 test/unit/session_test.rb delete mode 100644 test/unit/synapse_test.rb delete mode 100644 test/unit/topic_test.rb delete mode 100644 test/unit/user_test.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..83e16f80 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 00000000..53365a50 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,48 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +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 'spec_helper' +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 } + +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! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..913e28a6 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,92 @@ +# 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. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# 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 + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow 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. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # 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://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + 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 diff --git a/test/functional/.gitkeep b/test/functional/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/functional/in_metacode_sets_controller_test.rb b/test/functional/in_metacode_sets_controller_test.rb deleted file mode 100644 index f78ad458..00000000 --- a/test/functional/in_metacode_sets_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class InMetacodeSetsControllerTest < ActionController::TestCase - setup do - @in_metacode_set = in_metacode_sets(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:in_metacode_sets) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create in_metacode_set" do - assert_difference('InMetacodeSet.count') do - post :create, in_metacode_set: { } - end - - assert_redirected_to in_metacode_set_path(assigns(:in_metacode_set)) - end - - test "should show in_metacode_set" do - get :show, id: @in_metacode_set - assert_response :success - end - - test "should get edit" do - get :edit, id: @in_metacode_set - assert_response :success - end - - test "should update in_metacode_set" do - put :update, id: @in_metacode_set, in_metacode_set: { } - assert_redirected_to in_metacode_set_path(assigns(:in_metacode_set)) - end - - test "should destroy in_metacode_set" do - assert_difference('InMetacodeSet.count', -1) do - delete :destroy, id: @in_metacode_set - end - - assert_redirected_to in_metacode_sets_path - end -end diff --git a/test/functional/main_controller_test.rb b/test/functional/main_controller_test.rb deleted file mode 100644 index b7ec6bfc..00000000 --- a/test/functional/main_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MainControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/functional/mapping_controller_test.rb b/test/functional/mapping_controller_test.rb deleted file mode 100644 index 59fc534a..00000000 --- a/test/functional/mapping_controller_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' - -class MappingControllerTest < ActionController::TestCase - test "should get new" do - get :new - assert_response :success - end - -end diff --git a/test/functional/maps_controller_test.rb b/test/functional/maps_controller_test.rb deleted file mode 100644 index 9517ea55..00000000 --- a/test/functional/maps_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MapsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/functional/metacode_sets_controller_test.rb b/test/functional/metacode_sets_controller_test.rb deleted file mode 100644 index ec06c1e4..00000000 --- a/test/functional/metacode_sets_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class MetacodeSetsControllerTest < ActionController::TestCase - setup do - @metacode_set = metacode_sets(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:metacode_sets) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create metacode_set" do - assert_difference('MetacodeSet.count') do - post :create, metacode_set: { desc: @metacode_set.desc, mapperContributed: @metacode_set.mapperContributed, name: @metacode_set.name } - end - - assert_redirected_to metacode_set_path(assigns(:metacode_set)) - end - - test "should show metacode_set" do - get :show, id: @metacode_set - assert_response :success - end - - test "should get edit" do - get :edit, id: @metacode_set - assert_response :success - end - - test "should update metacode_set" do - put :update, id: @metacode_set, metacode_set: { desc: @metacode_set.desc, mapperContributed: @metacode_set.mapperContributed, name: @metacode_set.name } - assert_redirected_to metacode_set_path(assigns(:metacode_set)) - end - - test "should destroy metacode_set" do - assert_difference('MetacodeSet.count', -1) do - delete :destroy, id: @metacode_set - end - - assert_redirected_to metacode_sets_path - end -end diff --git a/test/functional/metacodes_controller_test.rb b/test/functional/metacodes_controller_test.rb deleted file mode 100644 index c15d468f..00000000 --- a/test/functional/metacodes_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class MetacodesControllerTest < ActionController::TestCase - setup do - @metacode = metacodes(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:metacodes) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create metacode" do - assert_difference('Metacode.count') do - post :create, metacode: { icon: @metacode.icon, name: @metacode.name } - end - - assert_redirected_to metacode_path(assigns(:metacode)) - end - - test "should show metacode" do - get :show, id: @metacode - assert_response :success - end - - test "should get edit" do - get :edit, id: @metacode - assert_response :success - end - - test "should update metacode" do - put :update, id: @metacode, metacode: { icon: @metacode.icon, name: @metacode.name } - assert_redirected_to metacode_path(assigns(:metacode)) - end - - test "should destroy metacode" do - assert_difference('Metacode.count', -1) do - delete :destroy, id: @metacode - end - - assert_redirected_to metacodes_path - end -end diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb deleted file mode 100644 index d30ebc38..00000000 --- a/test/functional/sessions_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SessionsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/functional/synapses_controller_test.rb b/test/functional/synapses_controller_test.rb deleted file mode 100644 index 42d864b0..00000000 --- a/test/functional/synapses_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SynapsesControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/functional/topics_controller_test.rb b/test/functional/topics_controller_test.rb deleted file mode 100644 index dd41edd9..00000000 --- a/test/functional/topics_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class TopicsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb deleted file mode 100644 index d23f1829..00000000 --- a/test/functional/users_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class UsersControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/integration/.gitkeep b/test/integration/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb deleted file mode 100644 index 3fea27b9..00000000 --- a/test/performance/browsing_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'test_helper' -require 'rails/performance_test_help' - -class BrowsingTest < ActionDispatch::PerformanceTest - # Refer to the documentation for all available options - # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] - # :output => 'tmp/performance', :formats => [:flat] } - - def test_homepage - get '/' - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 8bf1192f..00000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,13 +0,0 @@ -ENV["RAILS_ENV"] = "test" -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. - # - # Note: You'll currently still have to declare fixtures explicitly in integration tests - # -- they do not yet inherit this setting - fixtures :all - - # Add more helper methods to be used by all tests here... -end diff --git a/test/unit/.gitkeep b/test/unit/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/unit/helpers/in_metacode_sets_helper_test.rb b/test/unit/helpers/in_metacode_sets_helper_test.rb deleted file mode 100644 index 64eb689a..00000000 --- a/test/unit/helpers/in_metacode_sets_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class InMetacodeSetsHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/main_helper_test.rb b/test/unit/helpers/main_helper_test.rb deleted file mode 100644 index 22da3c40..00000000 --- a/test/unit/helpers/main_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MainHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/mapping_helper_test.rb b/test/unit/helpers/mapping_helper_test.rb deleted file mode 100644 index 5768ae1b..00000000 --- a/test/unit/helpers/mapping_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MappingHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/maps_helper_test.rb b/test/unit/helpers/maps_helper_test.rb deleted file mode 100644 index 0a0efccd..00000000 --- a/test/unit/helpers/maps_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MapsHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/metacode_sets_helper_test.rb b/test/unit/helpers/metacode_sets_helper_test.rb deleted file mode 100644 index d1983654..00000000 --- a/test/unit/helpers/metacode_sets_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MetacodeSetsHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/metacodes_helper_test.rb b/test/unit/helpers/metacodes_helper_test.rb deleted file mode 100644 index 2837d55f..00000000 --- a/test/unit/helpers/metacodes_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MetacodesHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/sessions_helper_test.rb b/test/unit/helpers/sessions_helper_test.rb deleted file mode 100644 index 7d44e096..00000000 --- a/test/unit/helpers/sessions_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class SessionsHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/synapses_helper_test.rb b/test/unit/helpers/synapses_helper_test.rb deleted file mode 100644 index c7a530a0..00000000 --- a/test/unit/helpers/synapses_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class SynapsesHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/topics_helper_test.rb b/test/unit/helpers/topics_helper_test.rb deleted file mode 100644 index 12cc0b4f..00000000 --- a/test/unit/helpers/topics_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class TopicsHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/users_helper_test.rb b/test/unit/helpers/users_helper_test.rb deleted file mode 100644 index 96af37a8..00000000 --- a/test/unit/helpers/users_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class UsersHelperTest < ActionView::TestCase -end diff --git a/test/unit/in_metacode_set_test.rb b/test/unit/in_metacode_set_test.rb deleted file mode 100644 index 1873f3d2..00000000 --- a/test/unit/in_metacode_set_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class InMetacodeSetTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/map_test.rb b/test/unit/map_test.rb deleted file mode 100644 index 033cf0ff..00000000 --- a/test/unit/map_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MapTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/mapping_test.rb b/test/unit/mapping_test.rb deleted file mode 100644 index 20115809..00000000 --- a/test/unit/mapping_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MappingTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/metacode_set_test.rb b/test/unit/metacode_set_test.rb deleted file mode 100644 index f92bc573..00000000 --- a/test/unit/metacode_set_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MetacodeSetTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/metacode_test.rb b/test/unit/metacode_test.rb deleted file mode 100644 index 7bfd318d..00000000 --- a/test/unit/metacode_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MetacodeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/session_test.rb b/test/unit/session_test.rb deleted file mode 100644 index 2d1bc1b0..00000000 --- a/test/unit/session_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SessionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/synapse_test.rb b/test/unit/synapse_test.rb deleted file mode 100644 index 50a6fe66..00000000 --- a/test/unit/synapse_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SynapseTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/topic_test.rb b/test/unit/topic_test.rb deleted file mode 100644 index 90522ee5..00000000 --- a/test/unit/topic_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class TopicTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb deleted file mode 100644 index 82f61e01..00000000 --- a/test/unit/user_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class UserTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end From 25117cf0e62b654cb50c1bdf00534bad372f965e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 12 Oct 2015 11:37:44 +0800 Subject: [PATCH 04/44] add rspec scaffold tests and a test db environment --- config/application.rb | 4 + config/database.yml.default | 13 +- config/initializers/devise.rb | 3 + spec/controllers/mappings_controller_spec.rb | 159 ++++++++++++++++++ spec/controllers/maps_controller_spec.rb | 159 ++++++++++++++++++ spec/controllers/metacodes_controller_spec.rb | 159 ++++++++++++++++++ spec/controllers/synapses_controller_spec.rb | 159 ++++++++++++++++++ spec/controllers/topics_controller_spec.rb | 159 ++++++++++++++++++ spec/models/map_spec.rb | 5 + spec/models/mapping_spec.rb | 5 + spec/models/metacode_spec.rb | 5 + spec/models/synapse_spec.rb | 5 + spec/models/topic_spec.rb | 5 + spec/routing/mappings_routing_spec.rb | 35 ++++ spec/routing/maps_routing_spec.rb | 35 ++++ spec/routing/metacodes_routing_spec.rb | 35 ++++ spec/routing/synapses_routing_spec.rb | 35 ++++ spec/routing/topics_routing_spec.rb | 35 ++++ spec/views/mappings/edit.html.erb_spec.rb | 14 ++ spec/views/mappings/index.html.erb_spec.rb | 14 ++ spec/views/mappings/new.html.erb_spec.rb | 14 ++ spec/views/mappings/show.html.erb_spec.rb | 11 ++ spec/views/maps/edit.html.erb_spec.rb | 14 ++ spec/views/maps/index.html.erb_spec.rb | 14 ++ spec/views/maps/new.html.erb_spec.rb | 14 ++ spec/views/maps/show.html.erb_spec.rb | 11 ++ spec/views/metacodes/edit.html.erb_spec.rb | 14 ++ spec/views/metacodes/index.html.erb_spec.rb | 14 ++ spec/views/metacodes/new.html.erb_spec.rb | 14 ++ spec/views/metacodes/show.html.erb_spec.rb | 11 ++ spec/views/synapses/edit.html.erb_spec.rb | 14 ++ spec/views/synapses/index.html.erb_spec.rb | 14 ++ spec/views/synapses/new.html.erb_spec.rb | 14 ++ spec/views/synapses/show.html.erb_spec.rb | 11 ++ spec/views/topics/edit.html.erb_spec.rb | 14 ++ spec/views/topics/index.html.erb_spec.rb | 14 ++ spec/views/topics/new.html.erb_spec.rb | 14 ++ spec/views/topics/show.html.erb_spec.rb | 11 ++ 38 files changed, 1277 insertions(+), 3 deletions(-) create mode 100644 spec/controllers/mappings_controller_spec.rb create mode 100644 spec/controllers/maps_controller_spec.rb create mode 100644 spec/controllers/metacodes_controller_spec.rb create mode 100644 spec/controllers/synapses_controller_spec.rb create mode 100644 spec/controllers/topics_controller_spec.rb create mode 100644 spec/models/map_spec.rb create mode 100644 spec/models/mapping_spec.rb create mode 100644 spec/models/metacode_spec.rb create mode 100644 spec/models/synapse_spec.rb create mode 100644 spec/models/topic_spec.rb create mode 100644 spec/routing/mappings_routing_spec.rb create mode 100644 spec/routing/maps_routing_spec.rb create mode 100644 spec/routing/metacodes_routing_spec.rb create mode 100644 spec/routing/synapses_routing_spec.rb create mode 100644 spec/routing/topics_routing_spec.rb create mode 100644 spec/views/mappings/edit.html.erb_spec.rb create mode 100644 spec/views/mappings/index.html.erb_spec.rb create mode 100644 spec/views/mappings/new.html.erb_spec.rb create mode 100644 spec/views/mappings/show.html.erb_spec.rb create mode 100644 spec/views/maps/edit.html.erb_spec.rb create mode 100644 spec/views/maps/index.html.erb_spec.rb create mode 100644 spec/views/maps/new.html.erb_spec.rb create mode 100644 spec/views/maps/show.html.erb_spec.rb create mode 100644 spec/views/metacodes/edit.html.erb_spec.rb create mode 100644 spec/views/metacodes/index.html.erb_spec.rb create mode 100644 spec/views/metacodes/new.html.erb_spec.rb create mode 100644 spec/views/metacodes/show.html.erb_spec.rb create mode 100644 spec/views/synapses/edit.html.erb_spec.rb create mode 100644 spec/views/synapses/index.html.erb_spec.rb create mode 100644 spec/views/synapses/new.html.erb_spec.rb create mode 100644 spec/views/synapses/show.html.erb_spec.rb create mode 100644 spec/views/topics/edit.html.erb_spec.rb create mode 100644 spec/views/topics/index.html.erb_spec.rb create mode 100644 spec/views/topics/new.html.erb_spec.rb create mode 100644 spec/views/topics/show.html.erb_spec.rb diff --git a/config/application.rb b/config/application.rb index d9f5f0f1..72ca47ea 100644 --- a/config/application.rb +++ b/config/application.rb @@ -56,5 +56,9 @@ module Metamaps # Version of your assets, change this if you want to expire all your assets config.assets.version = '2.0' + + config.generators do |g| + g.test_framework :rspec + end end end diff --git a/config/database.yml.default b/config/database.yml.default index 06bfae01..114a2cc4 100644 --- a/config/database.yml.default +++ b/config/database.yml.default @@ -1,10 +1,17 @@ -development: +defaults: &defaults min_messages: WARNING adapter: postgresql host: 127.0.0.1 port: 5432 encoding: unicode - database: metamap002_development pool: 5 username: postgres - password: "3112" \ No newline at end of file + password: "3112" + +development: + <<: *defaults + database: metamap002_development + +test: + <<: *defaults + database: metamap002_test diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 2924b11e..fd8033fd 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -13,6 +13,9 @@ Devise.setup do |config| if Rails.env.development? # this is for Connors localhost config.secret_key = 'f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614' end + if Rails.env.test? + config.secret_key = '81eb6e1c01efc2c78fde270d7c8233439488b20fac92bd08d0c1b02e98d2a32a7d603141e8ad7f7c01c24814bee81067074e17d868a0b1422df032af415be31c' + end if Rails.env.production? # this is for the heroku staging environment config.secret_key = 'd91ba0da95749174ee2b8922034783cbde4945409ed28b13383e18e72844beb74467f8199e9e216f0687cd2290c6e46bf74da24486d14bba3671d76c5b10c753' end diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb new file mode 100644 index 00000000..ae270bbe --- /dev/null +++ b/spec/controllers/mappings_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe MappingsController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Mapping. As you add validations to Mapping, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # MappingsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all mappings as @mappings" do + mapping = Mapping.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:mappings)).to eq([mapping]) + end + end + + describe "GET #show" do + it "assigns the requested mapping as @mapping" do + mapping = Mapping.create! valid_attributes + get :show, {:id => mapping.to_param}, valid_session + expect(assigns(:mapping)).to eq(mapping) + end + end + + describe "GET #new" do + it "assigns a new mapping as @mapping" do + get :new, {}, valid_session + expect(assigns(:mapping)).to be_a_new(Mapping) + end + end + + describe "GET #edit" do + it "assigns the requested mapping as @mapping" do + mapping = Mapping.create! valid_attributes + get :edit, {:id => mapping.to_param}, valid_session + expect(assigns(:mapping)).to eq(mapping) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Mapping" do + expect { + post :create, {:mapping => valid_attributes}, valid_session + }.to change(Mapping, :count).by(1) + end + + it "assigns a newly created mapping as @mapping" do + post :create, {:mapping => valid_attributes}, valid_session + expect(assigns(:mapping)).to be_a(Mapping) + expect(assigns(:mapping)).to be_persisted + end + + it "redirects to the created mapping" do + post :create, {:mapping => valid_attributes}, valid_session + expect(response).to redirect_to(Mapping.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved mapping as @mapping" do + post :create, {:mapping => invalid_attributes}, valid_session + expect(assigns(:mapping)).to be_a_new(Mapping) + end + + it "re-renders the 'new' template" do + post :create, {:mapping => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested mapping" do + mapping = Mapping.create! valid_attributes + put :update, {:id => mapping.to_param, :mapping => new_attributes}, valid_session + mapping.reload + skip("Add assertions for updated state") + end + + it "assigns the requested mapping as @mapping" do + mapping = Mapping.create! valid_attributes + put :update, {:id => mapping.to_param, :mapping => valid_attributes}, valid_session + expect(assigns(:mapping)).to eq(mapping) + end + + it "redirects to the mapping" do + mapping = Mapping.create! valid_attributes + put :update, {:id => mapping.to_param, :mapping => valid_attributes}, valid_session + expect(response).to redirect_to(mapping) + end + end + + context "with invalid params" do + it "assigns the mapping as @mapping" do + mapping = Mapping.create! valid_attributes + put :update, {:id => mapping.to_param, :mapping => invalid_attributes}, valid_session + expect(assigns(:mapping)).to eq(mapping) + end + + it "re-renders the 'edit' template" do + mapping = Mapping.create! valid_attributes + put :update, {:id => mapping.to_param, :mapping => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested mapping" do + mapping = Mapping.create! valid_attributes + expect { + delete :destroy, {:id => mapping.to_param}, valid_session + }.to change(Mapping, :count).by(-1) + end + + it "redirects to the mappings list" do + mapping = Mapping.create! valid_attributes + delete :destroy, {:id => mapping.to_param}, valid_session + expect(response).to redirect_to(mappings_url) + end + end + +end diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb new file mode 100644 index 00000000..9805b96e --- /dev/null +++ b/spec/controllers/maps_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe MapsController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Map. As you add validations to Map, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # MapsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all maps as @maps" do + map = Map.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:maps)).to eq([map]) + end + end + + describe "GET #show" do + it "assigns the requested map as @map" do + map = Map.create! valid_attributes + get :show, {:id => map.to_param}, valid_session + expect(assigns(:map)).to eq(map) + end + end + + describe "GET #new" do + it "assigns a new map as @map" do + get :new, {}, valid_session + expect(assigns(:map)).to be_a_new(Map) + end + end + + describe "GET #edit" do + it "assigns the requested map as @map" do + map = Map.create! valid_attributes + get :edit, {:id => map.to_param}, valid_session + expect(assigns(:map)).to eq(map) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Map" do + expect { + post :create, {:map => valid_attributes}, valid_session + }.to change(Map, :count).by(1) + end + + it "assigns a newly created map as @map" do + post :create, {:map => valid_attributes}, valid_session + expect(assigns(:map)).to be_a(Map) + expect(assigns(:map)).to be_persisted + end + + it "redirects to the created map" do + post :create, {:map => valid_attributes}, valid_session + expect(response).to redirect_to(Map.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved map as @map" do + post :create, {:map => invalid_attributes}, valid_session + expect(assigns(:map)).to be_a_new(Map) + end + + it "re-renders the 'new' template" do + post :create, {:map => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested map" do + map = Map.create! valid_attributes + put :update, {:id => map.to_param, :map => new_attributes}, valid_session + map.reload + skip("Add assertions for updated state") + end + + it "assigns the requested map as @map" do + map = Map.create! valid_attributes + put :update, {:id => map.to_param, :map => valid_attributes}, valid_session + expect(assigns(:map)).to eq(map) + end + + it "redirects to the map" do + map = Map.create! valid_attributes + put :update, {:id => map.to_param, :map => valid_attributes}, valid_session + expect(response).to redirect_to(map) + end + end + + context "with invalid params" do + it "assigns the map as @map" do + map = Map.create! valid_attributes + put :update, {:id => map.to_param, :map => invalid_attributes}, valid_session + expect(assigns(:map)).to eq(map) + end + + it "re-renders the 'edit' template" do + map = Map.create! valid_attributes + put :update, {:id => map.to_param, :map => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested map" do + map = Map.create! valid_attributes + expect { + delete :destroy, {:id => map.to_param}, valid_session + }.to change(Map, :count).by(-1) + end + + it "redirects to the maps list" do + map = Map.create! valid_attributes + delete :destroy, {:id => map.to_param}, valid_session + expect(response).to redirect_to(maps_url) + end + end + +end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb new file mode 100644 index 00000000..604609a0 --- /dev/null +++ b/spec/controllers/metacodes_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe MetacodesController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Metacode. As you add validations to Metacode, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # MetacodesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all metacodes as @metacodes" do + metacode = Metacode.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:metacodes)).to eq([metacode]) + end + end + + describe "GET #show" do + it "assigns the requested metacode as @metacode" do + metacode = Metacode.create! valid_attributes + get :show, {:id => metacode.to_param}, valid_session + expect(assigns(:metacode)).to eq(metacode) + end + end + + describe "GET #new" do + it "assigns a new metacode as @metacode" do + get :new, {}, valid_session + expect(assigns(:metacode)).to be_a_new(Metacode) + end + end + + describe "GET #edit" do + it "assigns the requested metacode as @metacode" do + metacode = Metacode.create! valid_attributes + get :edit, {:id => metacode.to_param}, valid_session + expect(assigns(:metacode)).to eq(metacode) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Metacode" do + expect { + post :create, {:metacode => valid_attributes}, valid_session + }.to change(Metacode, :count).by(1) + end + + it "assigns a newly created metacode as @metacode" do + post :create, {:metacode => valid_attributes}, valid_session + expect(assigns(:metacode)).to be_a(Metacode) + expect(assigns(:metacode)).to be_persisted + end + + it "redirects to the created metacode" do + post :create, {:metacode => valid_attributes}, valid_session + expect(response).to redirect_to(Metacode.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved metacode as @metacode" do + post :create, {:metacode => invalid_attributes}, valid_session + expect(assigns(:metacode)).to be_a_new(Metacode) + end + + it "re-renders the 'new' template" do + post :create, {:metacode => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested metacode" do + metacode = Metacode.create! valid_attributes + put :update, {:id => metacode.to_param, :metacode => new_attributes}, valid_session + metacode.reload + skip("Add assertions for updated state") + end + + it "assigns the requested metacode as @metacode" do + metacode = Metacode.create! valid_attributes + put :update, {:id => metacode.to_param, :metacode => valid_attributes}, valid_session + expect(assigns(:metacode)).to eq(metacode) + end + + it "redirects to the metacode" do + metacode = Metacode.create! valid_attributes + put :update, {:id => metacode.to_param, :metacode => valid_attributes}, valid_session + expect(response).to redirect_to(metacode) + end + end + + context "with invalid params" do + it "assigns the metacode as @metacode" do + metacode = Metacode.create! valid_attributes + put :update, {:id => metacode.to_param, :metacode => invalid_attributes}, valid_session + expect(assigns(:metacode)).to eq(metacode) + end + + it "re-renders the 'edit' template" do + metacode = Metacode.create! valid_attributes + put :update, {:id => metacode.to_param, :metacode => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested metacode" do + metacode = Metacode.create! valid_attributes + expect { + delete :destroy, {:id => metacode.to_param}, valid_session + }.to change(Metacode, :count).by(-1) + end + + it "redirects to the metacodes list" do + metacode = Metacode.create! valid_attributes + delete :destroy, {:id => metacode.to_param}, valid_session + expect(response).to redirect_to(metacodes_url) + end + end + +end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb new file mode 100644 index 00000000..c4fb35af --- /dev/null +++ b/spec/controllers/synapses_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe SynapsesController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Synapse. As you add validations to Synapse, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # SynapsesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all synapses as @synapses" do + synapse = Synapse.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:synapses)).to eq([synapse]) + end + end + + describe "GET #show" do + it "assigns the requested synapse as @synapse" do + synapse = Synapse.create! valid_attributes + get :show, {:id => synapse.to_param}, valid_session + expect(assigns(:synapse)).to eq(synapse) + end + end + + describe "GET #new" do + it "assigns a new synapse as @synapse" do + get :new, {}, valid_session + expect(assigns(:synapse)).to be_a_new(Synapse) + end + end + + describe "GET #edit" do + it "assigns the requested synapse as @synapse" do + synapse = Synapse.create! valid_attributes + get :edit, {:id => synapse.to_param}, valid_session + expect(assigns(:synapse)).to eq(synapse) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Synapse" do + expect { + post :create, {:synapse => valid_attributes}, valid_session + }.to change(Synapse, :count).by(1) + end + + it "assigns a newly created synapse as @synapse" do + post :create, {:synapse => valid_attributes}, valid_session + expect(assigns(:synapse)).to be_a(Synapse) + expect(assigns(:synapse)).to be_persisted + end + + it "redirects to the created synapse" do + post :create, {:synapse => valid_attributes}, valid_session + expect(response).to redirect_to(Synapse.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved synapse as @synapse" do + post :create, {:synapse => invalid_attributes}, valid_session + expect(assigns(:synapse)).to be_a_new(Synapse) + end + + it "re-renders the 'new' template" do + post :create, {:synapse => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested synapse" do + synapse = Synapse.create! valid_attributes + put :update, {:id => synapse.to_param, :synapse => new_attributes}, valid_session + synapse.reload + skip("Add assertions for updated state") + end + + it "assigns the requested synapse as @synapse" do + synapse = Synapse.create! valid_attributes + put :update, {:id => synapse.to_param, :synapse => valid_attributes}, valid_session + expect(assigns(:synapse)).to eq(synapse) + end + + it "redirects to the synapse" do + synapse = Synapse.create! valid_attributes + put :update, {:id => synapse.to_param, :synapse => valid_attributes}, valid_session + expect(response).to redirect_to(synapse) + end + end + + context "with invalid params" do + it "assigns the synapse as @synapse" do + synapse = Synapse.create! valid_attributes + put :update, {:id => synapse.to_param, :synapse => invalid_attributes}, valid_session + expect(assigns(:synapse)).to eq(synapse) + end + + it "re-renders the 'edit' template" do + synapse = Synapse.create! valid_attributes + put :update, {:id => synapse.to_param, :synapse => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested synapse" do + synapse = Synapse.create! valid_attributes + expect { + delete :destroy, {:id => synapse.to_param}, valid_session + }.to change(Synapse, :count).by(-1) + end + + it "redirects to the synapses list" do + synapse = Synapse.create! valid_attributes + delete :destroy, {:id => synapse.to_param}, valid_session + expect(response).to redirect_to(synapses_url) + end + end + +end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb new file mode 100644 index 00000000..d3e7b506 --- /dev/null +++ b/spec/controllers/topics_controller_spec.rb @@ -0,0 +1,159 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +RSpec.describe TopicsController, :type => :controller do + + # This should return the minimal set of attributes required to create a valid + # Topic. As you add validations to Topic, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # TopicsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "assigns all topics as @topics" do + topic = Topic.create! valid_attributes + get :index, {}, valid_session + expect(assigns(:topics)).to eq([topic]) + end + end + + describe "GET #show" do + it "assigns the requested topic as @topic" do + topic = Topic.create! valid_attributes + get :show, {:id => topic.to_param}, valid_session + expect(assigns(:topic)).to eq(topic) + end + end + + describe "GET #new" do + it "assigns a new topic as @topic" do + get :new, {}, valid_session + expect(assigns(:topic)).to be_a_new(Topic) + end + end + + describe "GET #edit" do + it "assigns the requested topic as @topic" do + topic = Topic.create! valid_attributes + get :edit, {:id => topic.to_param}, valid_session + expect(assigns(:topic)).to eq(topic) + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Topic" do + expect { + post :create, {:topic => valid_attributes}, valid_session + }.to change(Topic, :count).by(1) + end + + it "assigns a newly created topic as @topic" do + post :create, {:topic => valid_attributes}, valid_session + expect(assigns(:topic)).to be_a(Topic) + expect(assigns(:topic)).to be_persisted + end + + it "redirects to the created topic" do + post :create, {:topic => valid_attributes}, valid_session + expect(response).to redirect_to(Topic.last) + end + end + + context "with invalid params" do + it "assigns a newly created but unsaved topic as @topic" do + post :create, {:topic => invalid_attributes}, valid_session + expect(assigns(:topic)).to be_a_new(Topic) + end + + it "re-renders the 'new' template" do + post :create, {:topic => invalid_attributes}, valid_session + expect(response).to render_template("new") + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested topic" do + topic = Topic.create! valid_attributes + put :update, {:id => topic.to_param, :topic => new_attributes}, valid_session + topic.reload + skip("Add assertions for updated state") + end + + it "assigns the requested topic as @topic" do + topic = Topic.create! valid_attributes + put :update, {:id => topic.to_param, :topic => valid_attributes}, valid_session + expect(assigns(:topic)).to eq(topic) + end + + it "redirects to the topic" do + topic = Topic.create! valid_attributes + put :update, {:id => topic.to_param, :topic => valid_attributes}, valid_session + expect(response).to redirect_to(topic) + end + end + + context "with invalid params" do + it "assigns the topic as @topic" do + topic = Topic.create! valid_attributes + put :update, {:id => topic.to_param, :topic => invalid_attributes}, valid_session + expect(assigns(:topic)).to eq(topic) + end + + it "re-renders the 'edit' template" do + topic = Topic.create! valid_attributes + put :update, {:id => topic.to_param, :topic => invalid_attributes}, valid_session + expect(response).to render_template("edit") + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested topic" do + topic = Topic.create! valid_attributes + expect { + delete :destroy, {:id => topic.to_param}, valid_session + }.to change(Topic, :count).by(-1) + end + + it "redirects to the topics list" do + topic = Topic.create! valid_attributes + delete :destroy, {:id => topic.to_param}, valid_session + expect(response).to redirect_to(topics_url) + end + end + +end diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb new file mode 100644 index 00000000..dc475ba3 --- /dev/null +++ b/spec/models/map_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Map, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb new file mode 100644 index 00000000..e00c5074 --- /dev/null +++ b/spec/models/mapping_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Mapping, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb new file mode 100644 index 00000000..a548118a --- /dev/null +++ b/spec/models/metacode_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Metacode, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb new file mode 100644 index 00000000..d1faf2c8 --- /dev/null +++ b/spec/models/synapse_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Synapse, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb new file mode 100644 index 00000000..a52bb072 --- /dev/null +++ b/spec/models/topic_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Topic, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/routing/mappings_routing_spec.rb b/spec/routing/mappings_routing_spec.rb new file mode 100644 index 00000000..676124ba --- /dev/null +++ b/spec/routing/mappings_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe MappingsController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/mappings").to route_to("mappings#index") + end + + it "routes to #new" do + expect(:get => "/mappings/new").to route_to("mappings#new") + end + + it "routes to #show" do + expect(:get => "/mappings/1").to route_to("mappings#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/mappings/1/edit").to route_to("mappings#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/mappings").to route_to("mappings#create") + end + + it "routes to #update via PUT" do + expect(:put => "/mappings/1").to route_to("mappings#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/mappings/1").to route_to("mappings#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/maps_routing_spec.rb b/spec/routing/maps_routing_spec.rb new file mode 100644 index 00000000..ac36d46a --- /dev/null +++ b/spec/routing/maps_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe MapsController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/maps").to route_to("maps#index") + end + + it "routes to #new" do + expect(:get => "/maps/new").to route_to("maps#new") + end + + it "routes to #show" do + expect(:get => "/maps/1").to route_to("maps#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/maps/1/edit").to route_to("maps#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/maps").to route_to("maps#create") + end + + it "routes to #update via PUT" do + expect(:put => "/maps/1").to route_to("maps#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/maps/1").to route_to("maps#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/metacodes_routing_spec.rb b/spec/routing/metacodes_routing_spec.rb new file mode 100644 index 00000000..a16cd989 --- /dev/null +++ b/spec/routing/metacodes_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe MetacodesController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/metacodes").to route_to("metacodes#index") + end + + it "routes to #new" do + expect(:get => "/metacodes/new").to route_to("metacodes#new") + end + + it "routes to #show" do + expect(:get => "/metacodes/1").to route_to("metacodes#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/metacodes/1/edit").to route_to("metacodes#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/metacodes").to route_to("metacodes#create") + end + + it "routes to #update via PUT" do + expect(:put => "/metacodes/1").to route_to("metacodes#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/metacodes/1").to route_to("metacodes#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/synapses_routing_spec.rb b/spec/routing/synapses_routing_spec.rb new file mode 100644 index 00000000..98a55995 --- /dev/null +++ b/spec/routing/synapses_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe SynapsesController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/synapses").to route_to("synapses#index") + end + + it "routes to #new" do + expect(:get => "/synapses/new").to route_to("synapses#new") + end + + it "routes to #show" do + expect(:get => "/synapses/1").to route_to("synapses#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/synapses/1/edit").to route_to("synapses#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/synapses").to route_to("synapses#create") + end + + it "routes to #update via PUT" do + expect(:put => "/synapses/1").to route_to("synapses#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/synapses/1").to route_to("synapses#destroy", :id => "1") + end + + end +end diff --git a/spec/routing/topics_routing_spec.rb b/spec/routing/topics_routing_spec.rb new file mode 100644 index 00000000..3aca22cb --- /dev/null +++ b/spec/routing/topics_routing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe TopicsController, :type => :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/topics").to route_to("topics#index") + end + + it "routes to #new" do + expect(:get => "/topics/new").to route_to("topics#new") + end + + it "routes to #show" do + expect(:get => "/topics/1").to route_to("topics#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/topics/1/edit").to route_to("topics#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/topics").to route_to("topics#create") + end + + it "routes to #update via PUT" do + expect(:put => "/topics/1").to route_to("topics#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/topics/1").to route_to("topics#destroy", :id => "1") + end + + end +end diff --git a/spec/views/mappings/edit.html.erb_spec.rb b/spec/views/mappings/edit.html.erb_spec.rb new file mode 100644 index 00000000..8958be16 --- /dev/null +++ b/spec/views/mappings/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "mappings/edit", :type => :view do + before(:each) do + @mapping = assign(:mapping, Mapping.create!()) + end + + it "renders the edit mapping form" do + render + + assert_select "form[action=?][method=?]", mapping_path(@mapping), "post" do + end + end +end diff --git a/spec/views/mappings/index.html.erb_spec.rb b/spec/views/mappings/index.html.erb_spec.rb new file mode 100644 index 00000000..8f3b48b8 --- /dev/null +++ b/spec/views/mappings/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "mappings/index", :type => :view do + before(:each) do + assign(:mappings, [ + Mapping.create!(), + Mapping.create!() + ]) + end + + it "renders a list of mappings" do + render + end +end diff --git a/spec/views/mappings/new.html.erb_spec.rb b/spec/views/mappings/new.html.erb_spec.rb new file mode 100644 index 00000000..d050c7c6 --- /dev/null +++ b/spec/views/mappings/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "mappings/new", :type => :view do + before(:each) do + assign(:mapping, Mapping.new()) + end + + it "renders new mapping form" do + render + + assert_select "form[action=?][method=?]", mappings_path, "post" do + end + end +end diff --git a/spec/views/mappings/show.html.erb_spec.rb b/spec/views/mappings/show.html.erb_spec.rb new file mode 100644 index 00000000..ca2ccffe --- /dev/null +++ b/spec/views/mappings/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "mappings/show", :type => :view do + before(:each) do + @mapping = assign(:mapping, Mapping.create!()) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/maps/edit.html.erb_spec.rb b/spec/views/maps/edit.html.erb_spec.rb new file mode 100644 index 00000000..ac45567e --- /dev/null +++ b/spec/views/maps/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "maps/edit", :type => :view do + before(:each) do + @map = assign(:map, Map.create!()) + end + + it "renders the edit map form" do + render + + assert_select "form[action=?][method=?]", map_path(@map), "post" do + end + end +end diff --git a/spec/views/maps/index.html.erb_spec.rb b/spec/views/maps/index.html.erb_spec.rb new file mode 100644 index 00000000..98cf6323 --- /dev/null +++ b/spec/views/maps/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "maps/index", :type => :view do + before(:each) do + assign(:maps, [ + Map.create!(), + Map.create!() + ]) + end + + it "renders a list of maps" do + render + end +end diff --git a/spec/views/maps/new.html.erb_spec.rb b/spec/views/maps/new.html.erb_spec.rb new file mode 100644 index 00000000..2a314a9e --- /dev/null +++ b/spec/views/maps/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "maps/new", :type => :view do + before(:each) do + assign(:map, Map.new()) + end + + it "renders new map form" do + render + + assert_select "form[action=?][method=?]", maps_path, "post" do + end + end +end diff --git a/spec/views/maps/show.html.erb_spec.rb b/spec/views/maps/show.html.erb_spec.rb new file mode 100644 index 00000000..6a854ca2 --- /dev/null +++ b/spec/views/maps/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "maps/show", :type => :view do + before(:each) do + @map = assign(:map, Map.create!()) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/metacodes/edit.html.erb_spec.rb b/spec/views/metacodes/edit.html.erb_spec.rb new file mode 100644 index 00000000..0ace65ae --- /dev/null +++ b/spec/views/metacodes/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "metacodes/edit", :type => :view do + before(:each) do + @metacode = assign(:metacode, Metacode.create!()) + end + + it "renders the edit metacode form" do + render + + assert_select "form[action=?][method=?]", metacode_path(@metacode), "post" do + end + end +end diff --git a/spec/views/metacodes/index.html.erb_spec.rb b/spec/views/metacodes/index.html.erb_spec.rb new file mode 100644 index 00000000..1c41e3ce --- /dev/null +++ b/spec/views/metacodes/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "metacodes/index", :type => :view do + before(:each) do + assign(:metacodes, [ + Metacode.create!(), + Metacode.create!() + ]) + end + + it "renders a list of metacodes" do + render + end +end diff --git a/spec/views/metacodes/new.html.erb_spec.rb b/spec/views/metacodes/new.html.erb_spec.rb new file mode 100644 index 00000000..aeee099c --- /dev/null +++ b/spec/views/metacodes/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "metacodes/new", :type => :view do + before(:each) do + assign(:metacode, Metacode.new()) + end + + it "renders new metacode form" do + render + + assert_select "form[action=?][method=?]", metacodes_path, "post" do + end + end +end diff --git a/spec/views/metacodes/show.html.erb_spec.rb b/spec/views/metacodes/show.html.erb_spec.rb new file mode 100644 index 00000000..78d5da9e --- /dev/null +++ b/spec/views/metacodes/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "metacodes/show", :type => :view do + before(:each) do + @metacode = assign(:metacode, Metacode.create!()) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/synapses/edit.html.erb_spec.rb b/spec/views/synapses/edit.html.erb_spec.rb new file mode 100644 index 00000000..72157746 --- /dev/null +++ b/spec/views/synapses/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "synapses/edit", :type => :view do + before(:each) do + @synapse = assign(:synapse, Synapse.create!()) + end + + it "renders the edit synapse form" do + render + + assert_select "form[action=?][method=?]", synapse_path(@synapse), "post" do + end + end +end diff --git a/spec/views/synapses/index.html.erb_spec.rb b/spec/views/synapses/index.html.erb_spec.rb new file mode 100644 index 00000000..61c572f7 --- /dev/null +++ b/spec/views/synapses/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "synapses/index", :type => :view do + before(:each) do + assign(:synapses, [ + Synapse.create!(), + Synapse.create!() + ]) + end + + it "renders a list of synapses" do + render + end +end diff --git a/spec/views/synapses/new.html.erb_spec.rb b/spec/views/synapses/new.html.erb_spec.rb new file mode 100644 index 00000000..48ec6313 --- /dev/null +++ b/spec/views/synapses/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "synapses/new", :type => :view do + before(:each) do + assign(:synapse, Synapse.new()) + end + + it "renders new synapse form" do + render + + assert_select "form[action=?][method=?]", synapses_path, "post" do + end + end +end diff --git a/spec/views/synapses/show.html.erb_spec.rb b/spec/views/synapses/show.html.erb_spec.rb new file mode 100644 index 00000000..53cca260 --- /dev/null +++ b/spec/views/synapses/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "synapses/show", :type => :view do + before(:each) do + @synapse = assign(:synapse, Synapse.create!()) + end + + it "renders attributes in

" do + render + end +end diff --git a/spec/views/topics/edit.html.erb_spec.rb b/spec/views/topics/edit.html.erb_spec.rb new file mode 100644 index 00000000..81bd9c70 --- /dev/null +++ b/spec/views/topics/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "topics/edit", :type => :view do + before(:each) do + @topic = assign(:topic, Topic.create!()) + end + + it "renders the edit topic form" do + render + + assert_select "form[action=?][method=?]", topic_path(@topic), "post" do + end + end +end diff --git a/spec/views/topics/index.html.erb_spec.rb b/spec/views/topics/index.html.erb_spec.rb new file mode 100644 index 00000000..fea0c14d --- /dev/null +++ b/spec/views/topics/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "topics/index", :type => :view do + before(:each) do + assign(:topics, [ + Topic.create!(), + Topic.create!() + ]) + end + + it "renders a list of topics" do + render + end +end diff --git a/spec/views/topics/new.html.erb_spec.rb b/spec/views/topics/new.html.erb_spec.rb new file mode 100644 index 00000000..cd37ee22 --- /dev/null +++ b/spec/views/topics/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "topics/new", :type => :view do + before(:each) do + assign(:topic, Topic.new()) + end + + it "renders new topic form" do + render + + assert_select "form[action=?][method=?]", topics_path, "post" do + end + end +end diff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rb new file mode 100644 index 00000000..9bad98ee --- /dev/null +++ b/spec/views/topics/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "topics/show", :type => :view do + before(:each) do + @topic = assign(:topic, Topic.create!()) + end + + it "renders attributes in

" do + render + end +end From d913f50cf9bd5201466505f0b626aa515fc3fd19 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 12 Oct 2015 17:19:16 +0800 Subject: [PATCH 05/44] remove views specs and non-applicable routing specs --- spec/routing/mappings_routing_spec.rb | 12 ------------ spec/routing/maps_routing_spec.rb | 8 -------- spec/routing/metacodes_routing_spec.rb | 11 +++-------- spec/routing/synapses_routing_spec.rb | 12 ------------ spec/routing/topics_routing_spec.rb | 12 ------------ spec/views/mappings/edit.html.erb_spec.rb | 14 -------------- spec/views/mappings/index.html.erb_spec.rb | 14 -------------- spec/views/mappings/new.html.erb_spec.rb | 14 -------------- spec/views/mappings/show.html.erb_spec.rb | 11 ----------- spec/views/maps/edit.html.erb_spec.rb | 14 -------------- spec/views/maps/index.html.erb_spec.rb | 14 -------------- spec/views/maps/new.html.erb_spec.rb | 14 -------------- spec/views/maps/show.html.erb_spec.rb | 11 ----------- spec/views/metacodes/edit.html.erb_spec.rb | 14 -------------- spec/views/metacodes/index.html.erb_spec.rb | 14 -------------- spec/views/metacodes/new.html.erb_spec.rb | 14 -------------- spec/views/metacodes/show.html.erb_spec.rb | 11 ----------- spec/views/synapses/edit.html.erb_spec.rb | 14 -------------- spec/views/synapses/index.html.erb_spec.rb | 14 -------------- spec/views/synapses/new.html.erb_spec.rb | 14 -------------- spec/views/synapses/show.html.erb_spec.rb | 11 ----------- spec/views/topics/edit.html.erb_spec.rb | 14 -------------- spec/views/topics/index.html.erb_spec.rb | 14 -------------- spec/views/topics/new.html.erb_spec.rb | 14 -------------- spec/views/topics/show.html.erb_spec.rb | 11 ----------- 25 files changed, 3 insertions(+), 317 deletions(-) delete mode 100644 spec/views/mappings/edit.html.erb_spec.rb delete mode 100644 spec/views/mappings/index.html.erb_spec.rb delete mode 100644 spec/views/mappings/new.html.erb_spec.rb delete mode 100644 spec/views/mappings/show.html.erb_spec.rb delete mode 100644 spec/views/maps/edit.html.erb_spec.rb delete mode 100644 spec/views/maps/index.html.erb_spec.rb delete mode 100644 spec/views/maps/new.html.erb_spec.rb delete mode 100644 spec/views/maps/show.html.erb_spec.rb delete mode 100644 spec/views/metacodes/edit.html.erb_spec.rb delete mode 100644 spec/views/metacodes/index.html.erb_spec.rb delete mode 100644 spec/views/metacodes/new.html.erb_spec.rb delete mode 100644 spec/views/metacodes/show.html.erb_spec.rb delete mode 100644 spec/views/synapses/edit.html.erb_spec.rb delete mode 100644 spec/views/synapses/index.html.erb_spec.rb delete mode 100644 spec/views/synapses/new.html.erb_spec.rb delete mode 100644 spec/views/synapses/show.html.erb_spec.rb delete mode 100644 spec/views/topics/edit.html.erb_spec.rb delete mode 100644 spec/views/topics/index.html.erb_spec.rb delete mode 100644 spec/views/topics/new.html.erb_spec.rb delete mode 100644 spec/views/topics/show.html.erb_spec.rb diff --git a/spec/routing/mappings_routing_spec.rb b/spec/routing/mappings_routing_spec.rb index 676124ba..d8266398 100644 --- a/spec/routing/mappings_routing_spec.rb +++ b/spec/routing/mappings_routing_spec.rb @@ -3,22 +3,10 @@ require "rails_helper" RSpec.describe MappingsController, :type => :routing do describe "routing" do - it "routes to #index" do - expect(:get => "/mappings").to route_to("mappings#index") - end - - it "routes to #new" do - expect(:get => "/mappings/new").to route_to("mappings#new") - end - it "routes to #show" do expect(:get => "/mappings/1").to route_to("mappings#show", :id => "1") end - it "routes to #edit" do - expect(:get => "/mappings/1/edit").to route_to("mappings#edit", :id => "1") - end - it "routes to #create" do expect(:post => "/mappings").to route_to("mappings#create") end diff --git a/spec/routing/maps_routing_spec.rb b/spec/routing/maps_routing_spec.rb index ac36d46a..1e77be48 100644 --- a/spec/routing/maps_routing_spec.rb +++ b/spec/routing/maps_routing_spec.rb @@ -7,18 +7,10 @@ RSpec.describe MapsController, :type => :routing do expect(:get => "/maps").to route_to("maps#index") end - it "routes to #new" do - expect(:get => "/maps/new").to route_to("maps#new") - end - it "routes to #show" do expect(:get => "/maps/1").to route_to("maps#show", :id => "1") end - it "routes to #edit" do - expect(:get => "/maps/1/edit").to route_to("maps#edit", :id => "1") - end - it "routes to #create" do expect(:post => "/maps").to route_to("maps#create") end diff --git a/spec/routing/metacodes_routing_spec.rb b/spec/routing/metacodes_routing_spec.rb index a16cd989..2bc39be7 100644 --- a/spec/routing/metacodes_routing_spec.rb +++ b/spec/routing/metacodes_routing_spec.rb @@ -11,10 +11,6 @@ RSpec.describe MetacodesController, :type => :routing do expect(:get => "/metacodes/new").to route_to("metacodes#new") end - it "routes to #show" do - expect(:get => "/metacodes/1").to route_to("metacodes#show", :id => "1") - end - it "routes to #edit" do expect(:get => "/metacodes/1/edit").to route_to("metacodes#edit", :id => "1") end @@ -27,9 +23,8 @@ RSpec.describe MetacodesController, :type => :routing do expect(:put => "/metacodes/1").to route_to("metacodes#update", :id => "1") end - it "routes to #destroy" do - expect(:delete => "/metacodes/1").to route_to("metacodes#destroy", :id => "1") - end - + #it "routes to #destroy" do + # expect(:delete => "/metacodes/1").to route_to("metacodes#destroy", :id => "1") + #end end end diff --git a/spec/routing/synapses_routing_spec.rb b/spec/routing/synapses_routing_spec.rb index 98a55995..e0639bd0 100644 --- a/spec/routing/synapses_routing_spec.rb +++ b/spec/routing/synapses_routing_spec.rb @@ -3,22 +3,10 @@ require "rails_helper" RSpec.describe SynapsesController, :type => :routing do describe "routing" do - it "routes to #index" do - expect(:get => "/synapses").to route_to("synapses#index") - end - - it "routes to #new" do - expect(:get => "/synapses/new").to route_to("synapses#new") - end - it "routes to #show" do expect(:get => "/synapses/1").to route_to("synapses#show", :id => "1") end - it "routes to #edit" do - expect(:get => "/synapses/1/edit").to route_to("synapses#edit", :id => "1") - end - it "routes to #create" do expect(:post => "/synapses").to route_to("synapses#create") end diff --git a/spec/routing/topics_routing_spec.rb b/spec/routing/topics_routing_spec.rb index 3aca22cb..515e15bf 100644 --- a/spec/routing/topics_routing_spec.rb +++ b/spec/routing/topics_routing_spec.rb @@ -3,22 +3,10 @@ require "rails_helper" RSpec.describe TopicsController, :type => :routing do describe "routing" do - it "routes to #index" do - expect(:get => "/topics").to route_to("topics#index") - end - - it "routes to #new" do - expect(:get => "/topics/new").to route_to("topics#new") - end - it "routes to #show" do expect(:get => "/topics/1").to route_to("topics#show", :id => "1") end - it "routes to #edit" do - expect(:get => "/topics/1/edit").to route_to("topics#edit", :id => "1") - end - it "routes to #create" do expect(:post => "/topics").to route_to("topics#create") end diff --git a/spec/views/mappings/edit.html.erb_spec.rb b/spec/views/mappings/edit.html.erb_spec.rb deleted file mode 100644 index 8958be16..00000000 --- a/spec/views/mappings/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "mappings/edit", :type => :view do - before(:each) do - @mapping = assign(:mapping, Mapping.create!()) - end - - it "renders the edit mapping form" do - render - - assert_select "form[action=?][method=?]", mapping_path(@mapping), "post" do - end - end -end diff --git a/spec/views/mappings/index.html.erb_spec.rb b/spec/views/mappings/index.html.erb_spec.rb deleted file mode 100644 index 8f3b48b8..00000000 --- a/spec/views/mappings/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "mappings/index", :type => :view do - before(:each) do - assign(:mappings, [ - Mapping.create!(), - Mapping.create!() - ]) - end - - it "renders a list of mappings" do - render - end -end diff --git a/spec/views/mappings/new.html.erb_spec.rb b/spec/views/mappings/new.html.erb_spec.rb deleted file mode 100644 index d050c7c6..00000000 --- a/spec/views/mappings/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "mappings/new", :type => :view do - before(:each) do - assign(:mapping, Mapping.new()) - end - - it "renders new mapping form" do - render - - assert_select "form[action=?][method=?]", mappings_path, "post" do - end - end -end diff --git a/spec/views/mappings/show.html.erb_spec.rb b/spec/views/mappings/show.html.erb_spec.rb deleted file mode 100644 index ca2ccffe..00000000 --- a/spec/views/mappings/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "mappings/show", :type => :view do - before(:each) do - @mapping = assign(:mapping, Mapping.create!()) - end - - it "renders attributes in

" do - render - end -end diff --git a/spec/views/maps/edit.html.erb_spec.rb b/spec/views/maps/edit.html.erb_spec.rb deleted file mode 100644 index ac45567e..00000000 --- a/spec/views/maps/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "maps/edit", :type => :view do - before(:each) do - @map = assign(:map, Map.create!()) - end - - it "renders the edit map form" do - render - - assert_select "form[action=?][method=?]", map_path(@map), "post" do - end - end -end diff --git a/spec/views/maps/index.html.erb_spec.rb b/spec/views/maps/index.html.erb_spec.rb deleted file mode 100644 index 98cf6323..00000000 --- a/spec/views/maps/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "maps/index", :type => :view do - before(:each) do - assign(:maps, [ - Map.create!(), - Map.create!() - ]) - end - - it "renders a list of maps" do - render - end -end diff --git a/spec/views/maps/new.html.erb_spec.rb b/spec/views/maps/new.html.erb_spec.rb deleted file mode 100644 index 2a314a9e..00000000 --- a/spec/views/maps/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "maps/new", :type => :view do - before(:each) do - assign(:map, Map.new()) - end - - it "renders new map form" do - render - - assert_select "form[action=?][method=?]", maps_path, "post" do - end - end -end diff --git a/spec/views/maps/show.html.erb_spec.rb b/spec/views/maps/show.html.erb_spec.rb deleted file mode 100644 index 6a854ca2..00000000 --- a/spec/views/maps/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "maps/show", :type => :view do - before(:each) do - @map = assign(:map, Map.create!()) - end - - it "renders attributes in

" do - render - end -end diff --git a/spec/views/metacodes/edit.html.erb_spec.rb b/spec/views/metacodes/edit.html.erb_spec.rb deleted file mode 100644 index 0ace65ae..00000000 --- a/spec/views/metacodes/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "metacodes/edit", :type => :view do - before(:each) do - @metacode = assign(:metacode, Metacode.create!()) - end - - it "renders the edit metacode form" do - render - - assert_select "form[action=?][method=?]", metacode_path(@metacode), "post" do - end - end -end diff --git a/spec/views/metacodes/index.html.erb_spec.rb b/spec/views/metacodes/index.html.erb_spec.rb deleted file mode 100644 index 1c41e3ce..00000000 --- a/spec/views/metacodes/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "metacodes/index", :type => :view do - before(:each) do - assign(:metacodes, [ - Metacode.create!(), - Metacode.create!() - ]) - end - - it "renders a list of metacodes" do - render - end -end diff --git a/spec/views/metacodes/new.html.erb_spec.rb b/spec/views/metacodes/new.html.erb_spec.rb deleted file mode 100644 index aeee099c..00000000 --- a/spec/views/metacodes/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "metacodes/new", :type => :view do - before(:each) do - assign(:metacode, Metacode.new()) - end - - it "renders new metacode form" do - render - - assert_select "form[action=?][method=?]", metacodes_path, "post" do - end - end -end diff --git a/spec/views/metacodes/show.html.erb_spec.rb b/spec/views/metacodes/show.html.erb_spec.rb deleted file mode 100644 index 78d5da9e..00000000 --- a/spec/views/metacodes/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "metacodes/show", :type => :view do - before(:each) do - @metacode = assign(:metacode, Metacode.create!()) - end - - it "renders attributes in

" do - render - end -end diff --git a/spec/views/synapses/edit.html.erb_spec.rb b/spec/views/synapses/edit.html.erb_spec.rb deleted file mode 100644 index 72157746..00000000 --- a/spec/views/synapses/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "synapses/edit", :type => :view do - before(:each) do - @synapse = assign(:synapse, Synapse.create!()) - end - - it "renders the edit synapse form" do - render - - assert_select "form[action=?][method=?]", synapse_path(@synapse), "post" do - end - end -end diff --git a/spec/views/synapses/index.html.erb_spec.rb b/spec/views/synapses/index.html.erb_spec.rb deleted file mode 100644 index 61c572f7..00000000 --- a/spec/views/synapses/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "synapses/index", :type => :view do - before(:each) do - assign(:synapses, [ - Synapse.create!(), - Synapse.create!() - ]) - end - - it "renders a list of synapses" do - render - end -end diff --git a/spec/views/synapses/new.html.erb_spec.rb b/spec/views/synapses/new.html.erb_spec.rb deleted file mode 100644 index 48ec6313..00000000 --- a/spec/views/synapses/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "synapses/new", :type => :view do - before(:each) do - assign(:synapse, Synapse.new()) - end - - it "renders new synapse form" do - render - - assert_select "form[action=?][method=?]", synapses_path, "post" do - end - end -end diff --git a/spec/views/synapses/show.html.erb_spec.rb b/spec/views/synapses/show.html.erb_spec.rb deleted file mode 100644 index 53cca260..00000000 --- a/spec/views/synapses/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "synapses/show", :type => :view do - before(:each) do - @synapse = assign(:synapse, Synapse.create!()) - end - - it "renders attributes in

" do - render - end -end diff --git a/spec/views/topics/edit.html.erb_spec.rb b/spec/views/topics/edit.html.erb_spec.rb deleted file mode 100644 index 81bd9c70..00000000 --- a/spec/views/topics/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "topics/edit", :type => :view do - before(:each) do - @topic = assign(:topic, Topic.create!()) - end - - it "renders the edit topic form" do - render - - assert_select "form[action=?][method=?]", topic_path(@topic), "post" do - end - end -end diff --git a/spec/views/topics/index.html.erb_spec.rb b/spec/views/topics/index.html.erb_spec.rb deleted file mode 100644 index fea0c14d..00000000 --- a/spec/views/topics/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "topics/index", :type => :view do - before(:each) do - assign(:topics, [ - Topic.create!(), - Topic.create!() - ]) - end - - it "renders a list of topics" do - render - end -end diff --git a/spec/views/topics/new.html.erb_spec.rb b/spec/views/topics/new.html.erb_spec.rb deleted file mode 100644 index cd37ee22..00000000 --- a/spec/views/topics/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "topics/new", :type => :view do - before(:each) do - assign(:topic, Topic.new()) - end - - it "renders new topic form" do - render - - assert_select "form[action=?][method=?]", topics_path, "post" do - end - end -end diff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rb deleted file mode 100644 index 9bad98ee..00000000 --- a/spec/views/topics/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "topics/show", :type => :view do - before(:each) do - @topic = assign(:topic, Topic.create!()) - end - - it "renders attributes in

" do - render - end -end From e3a4207827e753d41129b65d576732739ea8bc89 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 19 Oct 2015 15:23:07 +0800 Subject: [PATCH 06/44] random_string helper function --- spec/spec_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 913e28a6..2ec8f7d0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -90,3 +90,8 @@ RSpec.configure do |config| Kernel.srand config.seed =end end + +def random_string(length = 10) + o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten + string = (0...length).map { o[rand(o.length)] }.join +end From 310222aef95dd622e86a137d4f5aec6f23aef775 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 19 Oct 2015 15:23:49 +0800 Subject: [PATCH 07/44] factories for synapse, topic, user --- spec/factories/synapses.rb | 9 +++++++++ spec/factories/topics.rb | 6 ++++++ spec/factories/users.rb | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 spec/factories/synapses.rb create mode 100644 spec/factories/topics.rb create mode 100644 spec/factories/users.rb diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb new file mode 100644 index 00000000..47ed5c04 --- /dev/null +++ b/spec/factories/synapses.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :synapse do + desc { random_string(10) } + category :to + permission :commons + association :node1, factory: :topic + association :node2, factory: :topic + end +end diff --git a/spec/factories/topics.rb b/spec/factories/topics.rb new file mode 100644 index 00000000..ecec31a3 --- /dev/null +++ b/spec/factories/topics.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :topic do + name { random_string(10) } + permission :commons + end +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 00000000..51633217 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :user do + name { random_string(10) } + email { random_string(10) + '@' + random_string(10) + '.com' } + code { random_string(8) } + joinedwithcode { random_string(8) } + password 'omgwtfbbq' + end +end From 6c4620afa6d49c75c78348b207295d613796621b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 27 Oct 2015 18:21:46 +0800 Subject: [PATCH 08/44] more qa --- metamaps-qa-steps.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metamaps-qa-steps.txt b/metamaps-qa-steps.txt index 36ea193a..d7ef5b98 100644 --- a/metamaps-qa-steps.txt +++ b/metamaps-qa-steps.txt @@ -22,3 +22,6 @@ Metamaps Test Suite 20) Rearrange one of your maps. Reload to see if the layout is preserved. 21) Set the screenshot for one of your maps, and verify the index of maps is updated. 22) Open two browsers on map #3 and verify that realtime editing works. +23) Log in as admin +24) Open the metacodes editor, and create a metacode. Verify it behaves normally (its icon shows up, you can assign it to topics, etc) +25) Create a new metacode set, and include metacodes. Switch to using this metacode set. Ensure the set shows up in the right click menu on a topic From 6f518be51d0fe71c8c2f201b932cf551e0a9ad87 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 27 Oct 2015 18:23:25 +0800 Subject: [PATCH 09/44] rspec tests rails4 Gemfile.lock --- Gemfile.lock | 316 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 184 insertions(+), 132 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5b431d4e..f8de0ac1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,58 +1,77 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.17) - actionpack (= 3.2.17) - mail (~> 2.5.4) - actionpack (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) + actionmailer (4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.4) + actionview (= 4.2.4) + activesupport (= 4.2.4) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.4) + activesupport (= 4.2.4) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) - activerecord (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - activesupport (3.2.17) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - arel (3.0.3) - aws-sdk (1.54.0) - aws-sdk-v1 (= 1.54.0) - aws-sdk-v1 (1.54.0) - json (~> 1.4) - nokogiri (>= 1.4.4) - bcrypt (3.1.7) - bcrypt (3.1.7-x86-mingw32) - best_in_place (2.1.0) - jquery-rails - rails (~> 3.1) - builder (3.0.4) - cancan (1.6.10) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.4) + activesupport (= 4.2.4) + globalid (>= 0.3.0) + activemodel (4.2.4) + activesupport (= 4.2.4) + builder (~> 3.1) + activerecord (4.2.4) + activemodel (= 4.2.4) + activesupport (= 4.2.4) + arel (~> 6.0) + activesupport (4.2.4) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.3) + aws-sdk (2.1.32) + aws-sdk-resources (= 2.1.32) + aws-sdk-core (2.1.32) + jmespath (~> 1.0) + aws-sdk-resources (2.1.32) + aws-sdk-core (= 2.1.32) + bcrypt (3.1.10) + best_in_place (3.0.3) + actionpack (>= 3.2) + railties (>= 3.2) + better_errors (2.1.1) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + rack (>= 0.9.0) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.2) + byebug (5.0.0) + columnize (= 0.9.0) + cancancan (1.13.1) climate_control (0.0.3) activesupport (>= 3.0) - cocaine (0.5.4) + cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) - coffee-rails (3.2.2) + coderay (1.1.0) + coffee-rails (4.1.0) coffee-script (>= 2.2.0) - railties (~> 3.2.0) - coffee-script (2.3.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.8.0) - devise (3.4.0) + coffee-script-source (1.9.1.1) + columnize (0.9.0) + debug_inspector (0.0.2) + devise (3.5.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) @@ -60,90 +79,115 @@ GEM thread_safe (~> 0.1) warden (~> 1.2.3) diff-lcs (1.2.5) - dotenv (2.0.0) + dotenv (2.0.2) erubis (2.7.0) - execjs (2.2.1) + execjs (2.6.0) ezcrypto (0.7.2) factory_girl (4.5.0) activesupport (>= 3.0.0) factory_girl_rails (4.5.0) factory_girl (~> 4.5.0) railties (>= 3.0.0) - formtastic (3.0.0) + formtastic (3.1.3) actionpack (>= 3.2.13) - formula (1.0.1) + formula (1.1.1) rails (> 3.0.0) - hike (1.2.3) - i18n (0.6.11) - jbuilder (0.8.2) - activesupport (>= 3.0.0) - journey (1.0.4) - jquery-rails (2.1.2) - railties (>= 3.1.0, < 5.0) - thor (~> 0.14) - json (1.8.1) - kaminari (0.16.1) + globalid (0.3.6) + activesupport (>= 4.1.0) + i18n (0.7.0) + jbuilder (2.3.2) + activesupport (>= 3.0.0, < 5) + multi_json (~> 1.2) + jmespath (1.1.3) + jquery-rails (4.0.5) + rails-dom-testing (~> 1.0) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-ui-rails (5.0.5) + railties (>= 3.2.16) + json (1.8.3) + kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.25.1) - mini_portile (0.6.0) - multi_json (1.10.1) - nokogiri (1.6.3.1) - mini_portile (= 0.6.0) - nokogiri (1.6.3.1-x86-mingw32) - mini_portile (= 0.6.0) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.3) + mime-types (>= 1.16, < 3) + method_source (0.8.2) + mime-types (2.6.2) + mimemagic (0.3.0) + mini_portile (0.6.2) + minitest (5.8.2) + multi_json (1.11.2) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) oauth (0.4.7) orm_adapter (0.5.0) - paperclip (4.2.0) - activemodel (>= 3.0.0) - activesupport (>= 3.0.0) - cocaine (~> 0.5.3) + paperclip (4.3.1) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + cocaine (~> 0.5.5) mime-types - pg (0.17.1) - pg (0.17.1-x86-mingw32) - polyglot (0.3.5) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.4) - rack - rack-test (0.6.2) + mimemagic (= 0.3.0) + pg (0.18.3) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.2.0) + byebug (~> 5.0) + pry (~> 0.10) + pry-rails (0.3.4) + pry (>= 0.9.10) + quiet_assets (1.1.0) + railties (>= 3.1, < 5.0) + rack (1.6.4) + rack-test (0.6.3) rack (>= 1.0) - rails (3.2.17) - actionmailer (= 3.2.17) - actionpack (= 3.2.17) - activerecord (= 3.2.17) - activeresource (= 3.2.17) - activesupport (= 3.2.17) - bundler (~> 1.0) - railties (= 3.2.17) - rails3-jquery-autocomplete (1.0.14) - rails (>= 3.0) - railties (3.2.17) - actionpack (= 3.2.17) - activesupport (= 3.2.17) - rack-ssl (~> 1.3.2) + rails (4.2.4) + actionmailer (= 4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) + activemodel (= 4.2.4) + activerecord (= 4.2.4) + activesupport (= 4.2.4) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.4) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.2) + loofah (~> 2.0) + rails3-jquery-autocomplete (1.0.15) + rails (>= 3.2) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.4) + rails_stdout_logging (0.0.4) + railties (4.2.4) + actionpack (= 4.2.4) + activesupport (= 4.2.4) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.3.2) - rdoc (3.12.2) - json (~> 1.4) - redis (3.1.0) - responders (1.1.1) - railties (>= 3.2, < 4.2) - rspec-core (3.3.1) + thor (>= 0.18.1, < 2.0) + rake (10.4.2) + redis (3.2.1) + responders (2.1.0) + railties (>= 4.2.0, < 5) + rspec-core (3.3.2) rspec-support (~> 3.3.0) - rspec-expectations (3.3.0) + rspec-expectations (3.3.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-mocks (3.3.1) + rspec-mocks (3.3.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-rails (3.3.2) + rspec-rails (3.3.3) actionpack (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3) railties (>= 3.0, < 4.3) @@ -152,24 +196,26 @@ GEM rspec-mocks (~> 3.3.0) rspec-support (~> 3.3.0) rspec-support (3.3.0) - sass (3.4.5) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - sprockets (2.2.2) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) + sass (3.4.19) + sass-rails (5.0.4) + railties (>= 4.0.0, < 5.0) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + slop (3.6.0) + sprockets (3.4.0) + rack (> 1, < 3) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) thor (0.19.1) - thread_safe (0.3.4) - tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - tzinfo (0.3.41) - uglifier (2.5.3) + thread_safe (0.3.5) + tilt (2.0.1) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (2.7.2) execjs (>= 0.3.0) json (>= 1.8.0) uservoice-ruby (0.0.11) @@ -181,30 +227,36 @@ GEM PLATFORMS ruby - x86-mingw32 DEPENDENCIES aws-sdk best_in_place - cancan - coffee-rails (~> 3.2.1) + better_errors + binding_of_caller + cancancan + coffee-rails devise dotenv factory_girl_rails formtastic formula - jbuilder (= 0.8.2) - jquery-rails (= 2.1.2) + jbuilder + jquery-rails + jquery-ui-rails json kaminari paperclip pg - rails (= 3.2.17) + pry-byebug + pry-rails + quiet_assets + rails (= 4.2.4) rails3-jquery-autocomplete + rails_12factor redis rspec-rails sass-rails - uglifier (>= 1.0.3) + uglifier uservoice-ruby BUNDLED WITH From 235d4f6c2408600e1d9e2aa57b1efa2ea35e9a65 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 15 Dec 2015 22:33:48 +0800 Subject: [PATCH 10/44] remove unneeded NEW tests, fix test.rb environment --- config/environments/test.rb | 2 +- spec/controllers/mappings_controller_spec.rb | 7 ------- spec/controllers/maps_controller_spec.rb | 7 ------- spec/controllers/synapses_controller_spec.rb | 7 ------- spec/controllers/topics_controller_spec.rb | 7 ------- 5 files changed, 1 insertion(+), 29 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 73003840..be83469c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -10,7 +10,7 @@ Metamaps::Application.configure do config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true + config.serve_static_files = true config.static_cache_control = "public, max-age=3600" # Show full error reports and disable caching diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index ae270bbe..371d0418 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -52,13 +52,6 @@ RSpec.describe MappingsController, :type => :controller do end end - describe "GET #new" do - it "assigns a new mapping as @mapping" do - get :new, {}, valid_session - expect(assigns(:mapping)).to be_a_new(Mapping) - end - end - describe "GET #edit" do it "assigns the requested mapping as @mapping" do mapping = Mapping.create! valid_attributes diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 9805b96e..9f66424e 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -52,13 +52,6 @@ RSpec.describe MapsController, :type => :controller do end end - describe "GET #new" do - it "assigns a new map as @map" do - get :new, {}, valid_session - expect(assigns(:map)).to be_a_new(Map) - end - end - describe "GET #edit" do it "assigns the requested map as @map" do map = Map.create! valid_attributes diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index c4fb35af..8f8d5187 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -52,13 +52,6 @@ RSpec.describe SynapsesController, :type => :controller do end end - describe "GET #new" do - it "assigns a new synapse as @synapse" do - get :new, {}, valid_session - expect(assigns(:synapse)).to be_a_new(Synapse) - end - end - describe "GET #edit" do it "assigns the requested synapse as @synapse" do synapse = Synapse.create! valid_attributes diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index d3e7b506..15c52e16 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -52,13 +52,6 @@ RSpec.describe TopicsController, :type => :controller do end end - describe "GET #new" do - it "assigns a new topic as @topic" do - get :new, {}, valid_session - expect(assigns(:topic)).to be_a_new(Topic) - end - end - describe "GET #edit" do it "assigns the requested topic as @topic" do topic = Topic.create! valid_attributes From 6148f55e1ca1c5baeba3ad0f4fa6346b6b720971 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 21:05:18 +0800 Subject: [PATCH 11/44] handle nil unsafe_uri in app conttroller function --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4278637f..c0de632a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -60,7 +60,7 @@ private def get_invite_link unsafe_uri = request.env["REQUEST_URI"] valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ - safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/" + safe_uri = unsafe_uri.try(:match, valid_url) ? unsafe_uri : "http://metamaps.cc/" @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") end end From be3924aa5453c12b827fba51cd68bff96f632022 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 21:32:50 +0800 Subject: [PATCH 12/44] setup bare minimum devise authentication in tests --- app/controllers/application_controller.rb | 13 ++++++++----- app/controllers/metacodes_controller.rb | 1 - spec/controllers/metacodes_controller_spec.rb | 4 ++++ spec/rails_helper.rb | 3 +++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c0de632a..1c6c3f35 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,17 +50,20 @@ private end def authenticated? + return nil if warden.nil? #rspec tests current_user end def admin? - current_user && current_user.admin + authenticated? && current_user.admin end def get_invite_link - unsafe_uri = request.env["REQUEST_URI"] - valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ - safe_uri = unsafe_uri.try(:match, valid_url) ? unsafe_uri : "http://metamaps.cc/" - @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") + unless warden.nil? # rspec tests + unsafe_uri = request.env["REQUEST_URI"] + valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ + safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/" + @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") + end end end diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 7a14f2a8..5d1e1367 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -1,5 +1,4 @@ class MetacodesController < ApplicationController - before_filter :require_admin, except: [:index] # GET /metacodes diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index 604609a0..c3e8a906 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -19,6 +19,10 @@ require 'rails_helper' # that an instance is receiving a specific message. RSpec.describe MetacodesController, :type => :controller do + before :each do + @user = User.new(admin: true) + sign_in @user + end # This should return the minimal set of attributes required to create a valid # Metacode. As you add validations to Metacode, be sure to diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 53365a50..d8e80d32 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -45,4 +45,7 @@ RSpec.configure do |config| # 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! + + config.include Devise::TestHelpers, type: :controller + end From ae1117338a145da5ee891ce7b8652caa100f6efa Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 22:16:02 +0800 Subject: [PATCH 13/44] set up devise authentication more srsly. Still doesn't pass the test though haha --- app/controllers/application_controller.rb | 11 ++++------- app/controllers/users_controller.rb | 1 - app/models/user.rb | 4 ++-- db/schema.rb | 2 +- db/seeds.rb | 16 ++++++++-------- spec/controllers/metacodes_controller_spec.rb | 2 +- spec/factories/users.rb | 3 ++- spec/rails_helper.rb | 18 +++--------------- spec/spec_helper.rb | 1 + spec/support/controller_helpers.rb | 14 ++++++++++++++ spec/support/factory_girl.rb | 4 ++++ 11 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 spec/support/controller_helpers.rb create mode 100644 spec/support/factory_girl.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c6c3f35..6a79915c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,7 +50,6 @@ private end def authenticated? - return nil if warden.nil? #rspec tests current_user end @@ -59,11 +58,9 @@ private end def get_invite_link - unless warden.nil? # rspec tests - unsafe_uri = request.env["REQUEST_URI"] - valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ - safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/" - @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") - end + unsafe_uri = request.env["REQUEST_URI"] + valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ + safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/" + @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bb645614..063ab866 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -101,5 +101,4 @@ class UsersController < ApplicationController def user_params params.require(:user).permit(:name, :email, :image, :password, :password_confirmation) end - end diff --git a/app/models/user.rb b/app/models/user.rb index fd3f4787..7c2a2202 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User < ActiveRecord::Base validates_uniqueness_of :name # done by devise validates_uniqueness_of :email # done by devise - validates :joinedwithcode, :presence => true, :inclusion => { :in => $codes, :message => "%{value} is not valid" }, :on => :create + validates :joinedwithcode, :presence => true, :inclusion => { :in => User.all.pluck(:code), :message => "%{value} is not valid" }, :on => :create # This method associates the attribute ":image" with a file attachment has_attached_file :image, :styles => { @@ -64,7 +64,7 @@ class User < ActiveRecord::Base #generate a random 8 letter/digit code that they can use to invite people def generate_code - self.code = rand(36**8).to_s(36) + self.code ||= rand(36**8).to_s(36) $codes.push(self.code) self.generation = get_generation! end diff --git a/db/schema.rb b/db/schema.rb index 45fbcf67..83cecc24 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151025083043) do +ActiveRecord::Schema.define(version: 20151028061513) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/db/seeds.rb b/db/seeds.rb index dc1d6906..3dbfab17 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,36 +2,36 @@ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). ## USERS -User.create({ +User.new({ name: 'user', email: 'user@user.com', password: 'toolsplusconsciousness', code: 'qwertyui', joinedwithcode: 'qwertyui', - admin: 'false', -}) + admin: 'false' +}).save -User.create({ +User.new({ name: 'admin', email: 'admin@admin.com', password: 'toolsplusconsciousness', code: 'iuytrewq', joinedwithcode: 'iuytrewq', - admin: 'true', -}) + admin: 'true' +}).save ## END USERS ## METACODES Metacode.create({ name: 'Action', icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', - color: '#BD6C85', + color: '#BD6C85' }) Metacode.create({ name: 'Activity', icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', - color: '#6EBF65', + color: '#6EBF65' }) Metacode.create({ diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index c3e8a906..a2f2738f 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -20,7 +20,7 @@ require 'rails_helper' RSpec.describe MetacodesController, :type => :controller do before :each do - @user = User.new(admin: true) + @user = create(:user, admin: true) sign_in @user end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 51633217..48edb0c1 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -3,7 +3,8 @@ FactoryGirl.define do name { random_string(10) } email { random_string(10) + '@' + random_string(10) + '.com' } code { random_string(8) } - joinedwithcode { random_string(8) } + joinedwithcode { code } password 'omgwtfbbq' + to_create {|instance| instance.save(validate: false) } # bypass validation of the joinedwithcode end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d8e80d32..f6d8fd0b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -7,20 +7,8 @@ require 'spec_helper' 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 } +# require all support files +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures @@ -47,5 +35,5 @@ RSpec.configure do |config| config.infer_spec_type_from_file_location! config.include Devise::TestHelpers, type: :controller - + config.include ControllerHelpers, type: :controller end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2ec8f7d0..be9f0d88 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,7 @@ # users commonly want. # # 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 diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb new file mode 100644 index 00000000..e8435ba7 --- /dev/null +++ b/spec/support/controller_helpers.rb @@ -0,0 +1,14 @@ +# https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs +module ControllerHelpers + def sign_in(user = create(:user)) + if user.nil? + # simulate unauthenticated + allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user}) + allow(controller).to receive(:current_user).and_return(nil) + else + # simulate authenticated + allow(request.env['warden']).to receive(:authenticate!).and_return(user) + allow(controller).to receive(:current_user).and_return(user) + end + end +end diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb new file mode 100644 index 00000000..de2a780d --- /dev/null +++ b/spec/support/factory_girl.rb @@ -0,0 +1,4 @@ +# lets you type create(:user) instead of FactoryGirl.create(:user) +RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods +end From 846d04dd0d4574094a850742b5735b8bfaca2ee5 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 22:19:58 +0800 Subject: [PATCH 14/44] rubocop style updates --- spec/controllers/mappings_controller_spec.rb | 116 +++++++++-------- spec/controllers/maps_controller_spec.rb | 116 +++++++++-------- spec/controllers/metacodes_controller_spec.rb | 119 +++++++++--------- spec/controllers/synapses_controller_spec.rb | 116 +++++++++-------- spec/controllers/topics_controller_spec.rb | 116 +++++++++-------- spec/factories/synapses.rb | 4 +- spec/factories/users.rb | 2 +- spec/models/map_spec.rb | 2 +- spec/models/mapping_spec.rb | 2 +- spec/models/metacode_spec.rb | 2 +- spec/models/synapse_spec.rb | 2 +- spec/models/topic_spec.rb | 2 +- spec/rails_helper.rb | 2 +- spec/routing/mappings_routing_spec.rb | 24 ++-- spec/routing/maps_routing_spec.rb | 28 ++--- spec/routing/metacodes_routing_spec.rb | 31 +++-- spec/routing/synapses_routing_spec.rb | 24 ++-- spec/routing/topics_routing_spec.rb | 24 ++-- spec/spec_helper.rb | 98 +++++++-------- spec/support/controller_helpers.rb | 2 +- spec/support/factory_girl.rb | 2 +- 21 files changed, 407 insertions(+), 427 deletions(-) diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index 371d0418..1fc3e181 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -18,135 +18,133 @@ require 'rails_helper' # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -RSpec.describe MappingsController, :type => :controller do - +RSpec.describe MappingsController, type: :controller do # This should return the minimal set of attributes required to create a valid # Mapping. As you add validations to Mapping, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + skip('Add a hash of attributes valid for your model') + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # MappingsController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all mappings as @mappings" do + describe 'GET #index' do + it 'assigns all mappings as @mappings' do mapping = Mapping.create! valid_attributes get :index, {}, valid_session expect(assigns(:mappings)).to eq([mapping]) end end - describe "GET #show" do - it "assigns the requested mapping as @mapping" do + describe 'GET #show' do + it 'assigns the requested mapping as @mapping' do mapping = Mapping.create! valid_attributes - get :show, {:id => mapping.to_param}, valid_session + get :show, { id: mapping.to_param }, valid_session expect(assigns(:mapping)).to eq(mapping) end end - describe "GET #edit" do - it "assigns the requested mapping as @mapping" do + describe 'GET #edit' do + it 'assigns the requested mapping as @mapping' do mapping = Mapping.create! valid_attributes - get :edit, {:id => mapping.to_param}, valid_session + get :edit, { id: mapping.to_param }, valid_session expect(assigns(:mapping)).to eq(mapping) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Mapping" do - expect { - post :create, {:mapping => valid_attributes}, valid_session - }.to change(Mapping, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Mapping' do + expect do + post :create, { mapping: valid_attributes }, valid_session + end.to change(Mapping, :count).by(1) end - it "assigns a newly created mapping as @mapping" do - post :create, {:mapping => valid_attributes}, valid_session + it 'assigns a newly created mapping as @mapping' do + post :create, { mapping: valid_attributes }, valid_session expect(assigns(:mapping)).to be_a(Mapping) expect(assigns(:mapping)).to be_persisted end - it "redirects to the created mapping" do - post :create, {:mapping => valid_attributes}, valid_session + it 'redirects to the created mapping' do + post :create, { mapping: valid_attributes }, valid_session expect(response).to redirect_to(Mapping.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved mapping as @mapping" do - post :create, {:mapping => invalid_attributes}, valid_session + context 'with invalid params' do + it 'assigns a newly created but unsaved mapping as @mapping' do + post :create, { mapping: invalid_attributes }, valid_session expect(assigns(:mapping)).to be_a_new(Mapping) end it "re-renders the 'new' template" do - post :create, {:mapping => invalid_attributes}, valid_session - expect(response).to render_template("new") + post :create, { mapping: invalid_attributes }, valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested mapping" do - mapping = Mapping.create! valid_attributes - put :update, {:id => mapping.to_param, :mapping => new_attributes}, valid_session - mapping.reload - skip("Add assertions for updated state") + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') end - it "assigns the requested mapping as @mapping" do + it 'updates the requested mapping' do mapping = Mapping.create! valid_attributes - put :update, {:id => mapping.to_param, :mapping => valid_attributes}, valid_session + put :update, { id: mapping.to_param, mapping: new_attributes }, valid_session + mapping.reload + skip('Add assertions for updated state') + end + + it 'assigns the requested mapping as @mapping' do + mapping = Mapping.create! valid_attributes + put :update, { id: mapping.to_param, mapping: valid_attributes }, valid_session expect(assigns(:mapping)).to eq(mapping) end - it "redirects to the mapping" do + it 'redirects to the mapping' do mapping = Mapping.create! valid_attributes - put :update, {:id => mapping.to_param, :mapping => valid_attributes}, valid_session + put :update, { id: mapping.to_param, mapping: valid_attributes }, valid_session expect(response).to redirect_to(mapping) end end - context "with invalid params" do - it "assigns the mapping as @mapping" do + context 'with invalid params' do + it 'assigns the mapping as @mapping' do mapping = Mapping.create! valid_attributes - put :update, {:id => mapping.to_param, :mapping => invalid_attributes}, valid_session + put :update, { id: mapping.to_param, mapping: invalid_attributes }, valid_session expect(assigns(:mapping)).to eq(mapping) end it "re-renders the 'edit' template" do mapping = Mapping.create! valid_attributes - put :update, {:id => mapping.to_param, :mapping => invalid_attributes}, valid_session - expect(response).to render_template("edit") + put :update, { id: mapping.to_param, mapping: invalid_attributes }, valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested mapping" do + describe 'DELETE #destroy' do + it 'destroys the requested mapping' do mapping = Mapping.create! valid_attributes - expect { - delete :destroy, {:id => mapping.to_param}, valid_session - }.to change(Mapping, :count).by(-1) + expect do + delete :destroy, { id: mapping.to_param }, valid_session + end.to change(Mapping, :count).by(-1) end - it "redirects to the mappings list" do + it 'redirects to the mappings list' do mapping = Mapping.create! valid_attributes - delete :destroy, {:id => mapping.to_param}, valid_session + delete :destroy, { id: mapping.to_param }, valid_session expect(response).to redirect_to(mappings_url) end end - end diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 9f66424e..ff16c87b 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -18,135 +18,133 @@ require 'rails_helper' # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -RSpec.describe MapsController, :type => :controller do - +RSpec.describe MapsController, type: :controller do # This should return the minimal set of attributes required to create a valid # Map. As you add validations to Map, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + skip('Add a hash of attributes valid for your model') + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # MapsController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all maps as @maps" do + describe 'GET #index' do + it 'assigns all maps as @maps' do map = Map.create! valid_attributes get :index, {}, valid_session expect(assigns(:maps)).to eq([map]) end end - describe "GET #show" do - it "assigns the requested map as @map" do + describe 'GET #show' do + it 'assigns the requested map as @map' do map = Map.create! valid_attributes - get :show, {:id => map.to_param}, valid_session + get :show, { id: map.to_param }, valid_session expect(assigns(:map)).to eq(map) end end - describe "GET #edit" do - it "assigns the requested map as @map" do + describe 'GET #edit' do + it 'assigns the requested map as @map' do map = Map.create! valid_attributes - get :edit, {:id => map.to_param}, valid_session + get :edit, { id: map.to_param }, valid_session expect(assigns(:map)).to eq(map) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Map" do - expect { - post :create, {:map => valid_attributes}, valid_session - }.to change(Map, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Map' do + expect do + post :create, { map: valid_attributes }, valid_session + end.to change(Map, :count).by(1) end - it "assigns a newly created map as @map" do - post :create, {:map => valid_attributes}, valid_session + it 'assigns a newly created map as @map' do + post :create, { map: valid_attributes }, valid_session expect(assigns(:map)).to be_a(Map) expect(assigns(:map)).to be_persisted end - it "redirects to the created map" do - post :create, {:map => valid_attributes}, valid_session + it 'redirects to the created map' do + post :create, { map: valid_attributes }, valid_session expect(response).to redirect_to(Map.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved map as @map" do - post :create, {:map => invalid_attributes}, valid_session + context 'with invalid params' do + it 'assigns a newly created but unsaved map as @map' do + post :create, { map: invalid_attributes }, valid_session expect(assigns(:map)).to be_a_new(Map) end it "re-renders the 'new' template" do - post :create, {:map => invalid_attributes}, valid_session - expect(response).to render_template("new") + post :create, { map: invalid_attributes }, valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested map" do - map = Map.create! valid_attributes - put :update, {:id => map.to_param, :map => new_attributes}, valid_session - map.reload - skip("Add assertions for updated state") + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') end - it "assigns the requested map as @map" do + it 'updates the requested map' do map = Map.create! valid_attributes - put :update, {:id => map.to_param, :map => valid_attributes}, valid_session + put :update, { id: map.to_param, map: new_attributes }, valid_session + map.reload + skip('Add assertions for updated state') + end + + it 'assigns the requested map as @map' do + map = Map.create! valid_attributes + put :update, { id: map.to_param, map: valid_attributes }, valid_session expect(assigns(:map)).to eq(map) end - it "redirects to the map" do + it 'redirects to the map' do map = Map.create! valid_attributes - put :update, {:id => map.to_param, :map => valid_attributes}, valid_session + put :update, { id: map.to_param, map: valid_attributes }, valid_session expect(response).to redirect_to(map) end end - context "with invalid params" do - it "assigns the map as @map" do + context 'with invalid params' do + it 'assigns the map as @map' do map = Map.create! valid_attributes - put :update, {:id => map.to_param, :map => invalid_attributes}, valid_session + put :update, { id: map.to_param, map: invalid_attributes }, valid_session expect(assigns(:map)).to eq(map) end it "re-renders the 'edit' template" do map = Map.create! valid_attributes - put :update, {:id => map.to_param, :map => invalid_attributes}, valid_session - expect(response).to render_template("edit") + put :update, { id: map.to_param, map: invalid_attributes }, valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested map" do + describe 'DELETE #destroy' do + it 'destroys the requested map' do map = Map.create! valid_attributes - expect { - delete :destroy, {:id => map.to_param}, valid_session - }.to change(Map, :count).by(-1) + expect do + delete :destroy, { id: map.to_param }, valid_session + end.to change(Map, :count).by(-1) end - it "redirects to the maps list" do + it 'redirects to the maps list' do map = Map.create! valid_attributes - delete :destroy, {:id => map.to_param}, valid_session + delete :destroy, { id: map.to_param }, valid_session expect(response).to redirect_to(maps_url) end end - end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index a2f2738f..6f307cb6 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -18,7 +18,7 @@ require 'rails_helper' # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -RSpec.describe MetacodesController, :type => :controller do +RSpec.describe MetacodesController, type: :controller do before :each do @user = create(:user, admin: true) sign_in @user @@ -27,137 +27,136 @@ RSpec.describe MetacodesController, :type => :controller do # This should return the minimal set of attributes required to create a valid # Metacode. As you add validations to Metacode, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + skip('Add a hash of attributes valid for your model') + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # MetacodesController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all metacodes as @metacodes" do + describe 'GET #index' do + it 'assigns all metacodes as @metacodes' do metacode = Metacode.create! valid_attributes get :index, {}, valid_session expect(assigns(:metacodes)).to eq([metacode]) end end - describe "GET #show" do - it "assigns the requested metacode as @metacode" do + describe 'GET #show' do + it 'assigns the requested metacode as @metacode' do metacode = Metacode.create! valid_attributes - get :show, {:id => metacode.to_param}, valid_session + get :show, { id: metacode.to_param }, valid_session expect(assigns(:metacode)).to eq(metacode) end end - describe "GET #new" do - it "assigns a new metacode as @metacode" do + describe 'GET #new' do + it 'assigns a new metacode as @metacode' do get :new, {}, valid_session expect(assigns(:metacode)).to be_a_new(Metacode) end end - describe "GET #edit" do - it "assigns the requested metacode as @metacode" do + describe 'GET #edit' do + it 'assigns the requested metacode as @metacode' do metacode = Metacode.create! valid_attributes - get :edit, {:id => metacode.to_param}, valid_session + get :edit, { id: metacode.to_param }, valid_session expect(assigns(:metacode)).to eq(metacode) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Metacode" do - expect { - post :create, {:metacode => valid_attributes}, valid_session - }.to change(Metacode, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Metacode' do + expect do + post :create, { metacode: valid_attributes }, valid_session + end.to change(Metacode, :count).by(1) end - it "assigns a newly created metacode as @metacode" do - post :create, {:metacode => valid_attributes}, valid_session + it 'assigns a newly created metacode as @metacode' do + post :create, { metacode: valid_attributes }, valid_session expect(assigns(:metacode)).to be_a(Metacode) expect(assigns(:metacode)).to be_persisted end - it "redirects to the created metacode" do - post :create, {:metacode => valid_attributes}, valid_session + it 'redirects to the created metacode' do + post :create, { metacode: valid_attributes }, valid_session expect(response).to redirect_to(Metacode.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved metacode as @metacode" do - post :create, {:metacode => invalid_attributes}, valid_session + context 'with invalid params' do + it 'assigns a newly created but unsaved metacode as @metacode' do + post :create, { metacode: invalid_attributes }, valid_session expect(assigns(:metacode)).to be_a_new(Metacode) end it "re-renders the 'new' template" do - post :create, {:metacode => invalid_attributes}, valid_session - expect(response).to render_template("new") + post :create, { metacode: invalid_attributes }, valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested metacode" do - metacode = Metacode.create! valid_attributes - put :update, {:id => metacode.to_param, :metacode => new_attributes}, valid_session - metacode.reload - skip("Add assertions for updated state") + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') end - it "assigns the requested metacode as @metacode" do + it 'updates the requested metacode' do metacode = Metacode.create! valid_attributes - put :update, {:id => metacode.to_param, :metacode => valid_attributes}, valid_session + put :update, { id: metacode.to_param, metacode: new_attributes }, valid_session + metacode.reload + skip('Add assertions for updated state') + end + + it 'assigns the requested metacode as @metacode' do + metacode = Metacode.create! valid_attributes + put :update, { id: metacode.to_param, metacode: valid_attributes }, valid_session expect(assigns(:metacode)).to eq(metacode) end - it "redirects to the metacode" do + it 'redirects to the metacode' do metacode = Metacode.create! valid_attributes - put :update, {:id => metacode.to_param, :metacode => valid_attributes}, valid_session + put :update, { id: metacode.to_param, metacode: valid_attributes }, valid_session expect(response).to redirect_to(metacode) end end - context "with invalid params" do - it "assigns the metacode as @metacode" do + context 'with invalid params' do + it 'assigns the metacode as @metacode' do metacode = Metacode.create! valid_attributes - put :update, {:id => metacode.to_param, :metacode => invalid_attributes}, valid_session + put :update, { id: metacode.to_param, metacode: invalid_attributes }, valid_session expect(assigns(:metacode)).to eq(metacode) end it "re-renders the 'edit' template" do metacode = Metacode.create! valid_attributes - put :update, {:id => metacode.to_param, :metacode => invalid_attributes}, valid_session - expect(response).to render_template("edit") + put :update, { id: metacode.to_param, metacode: invalid_attributes }, valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested metacode" do + describe 'DELETE #destroy' do + it 'destroys the requested metacode' do metacode = Metacode.create! valid_attributes - expect { - delete :destroy, {:id => metacode.to_param}, valid_session - }.to change(Metacode, :count).by(-1) + expect do + delete :destroy, { id: metacode.to_param }, valid_session + end.to change(Metacode, :count).by(-1) end - it "redirects to the metacodes list" do + it 'redirects to the metacodes list' do metacode = Metacode.create! valid_attributes - delete :destroy, {:id => metacode.to_param}, valid_session + delete :destroy, { id: metacode.to_param }, valid_session expect(response).to redirect_to(metacodes_url) end end - end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 8f8d5187..62f9c6ac 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -18,135 +18,133 @@ require 'rails_helper' # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -RSpec.describe SynapsesController, :type => :controller do - +RSpec.describe SynapsesController, type: :controller do # This should return the minimal set of attributes required to create a valid # Synapse. As you add validations to Synapse, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + skip('Add a hash of attributes valid for your model') + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # SynapsesController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all synapses as @synapses" do + describe 'GET #index' do + it 'assigns all synapses as @synapses' do synapse = Synapse.create! valid_attributes get :index, {}, valid_session expect(assigns(:synapses)).to eq([synapse]) end end - describe "GET #show" do - it "assigns the requested synapse as @synapse" do + describe 'GET #show' do + it 'assigns the requested synapse as @synapse' do synapse = Synapse.create! valid_attributes - get :show, {:id => synapse.to_param}, valid_session + get :show, { id: synapse.to_param }, valid_session expect(assigns(:synapse)).to eq(synapse) end end - describe "GET #edit" do - it "assigns the requested synapse as @synapse" do + describe 'GET #edit' do + it 'assigns the requested synapse as @synapse' do synapse = Synapse.create! valid_attributes - get :edit, {:id => synapse.to_param}, valid_session + get :edit, { id: synapse.to_param }, valid_session expect(assigns(:synapse)).to eq(synapse) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Synapse" do - expect { - post :create, {:synapse => valid_attributes}, valid_session - }.to change(Synapse, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Synapse' do + expect do + post :create, { synapse: valid_attributes }, valid_session + end.to change(Synapse, :count).by(1) end - it "assigns a newly created synapse as @synapse" do - post :create, {:synapse => valid_attributes}, valid_session + it 'assigns a newly created synapse as @synapse' do + post :create, { synapse: valid_attributes }, valid_session expect(assigns(:synapse)).to be_a(Synapse) expect(assigns(:synapse)).to be_persisted end - it "redirects to the created synapse" do - post :create, {:synapse => valid_attributes}, valid_session + it 'redirects to the created synapse' do + post :create, { synapse: valid_attributes }, valid_session expect(response).to redirect_to(Synapse.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved synapse as @synapse" do - post :create, {:synapse => invalid_attributes}, valid_session + context 'with invalid params' do + it 'assigns a newly created but unsaved synapse as @synapse' do + post :create, { synapse: invalid_attributes }, valid_session expect(assigns(:synapse)).to be_a_new(Synapse) end it "re-renders the 'new' template" do - post :create, {:synapse => invalid_attributes}, valid_session - expect(response).to render_template("new") + post :create, { synapse: invalid_attributes }, valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested synapse" do - synapse = Synapse.create! valid_attributes - put :update, {:id => synapse.to_param, :synapse => new_attributes}, valid_session - synapse.reload - skip("Add assertions for updated state") + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') end - it "assigns the requested synapse as @synapse" do + it 'updates the requested synapse' do synapse = Synapse.create! valid_attributes - put :update, {:id => synapse.to_param, :synapse => valid_attributes}, valid_session + put :update, { id: synapse.to_param, synapse: new_attributes }, valid_session + synapse.reload + skip('Add assertions for updated state') + end + + it 'assigns the requested synapse as @synapse' do + synapse = Synapse.create! valid_attributes + put :update, { id: synapse.to_param, synapse: valid_attributes }, valid_session expect(assigns(:synapse)).to eq(synapse) end - it "redirects to the synapse" do + it 'redirects to the synapse' do synapse = Synapse.create! valid_attributes - put :update, {:id => synapse.to_param, :synapse => valid_attributes}, valid_session + put :update, { id: synapse.to_param, synapse: valid_attributes }, valid_session expect(response).to redirect_to(synapse) end end - context "with invalid params" do - it "assigns the synapse as @synapse" do + context 'with invalid params' do + it 'assigns the synapse as @synapse' do synapse = Synapse.create! valid_attributes - put :update, {:id => synapse.to_param, :synapse => invalid_attributes}, valid_session + put :update, { id: synapse.to_param, synapse: invalid_attributes }, valid_session expect(assigns(:synapse)).to eq(synapse) end it "re-renders the 'edit' template" do synapse = Synapse.create! valid_attributes - put :update, {:id => synapse.to_param, :synapse => invalid_attributes}, valid_session - expect(response).to render_template("edit") + put :update, { id: synapse.to_param, synapse: invalid_attributes }, valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested synapse" do + describe 'DELETE #destroy' do + it 'destroys the requested synapse' do synapse = Synapse.create! valid_attributes - expect { - delete :destroy, {:id => synapse.to_param}, valid_session - }.to change(Synapse, :count).by(-1) + expect do + delete :destroy, { id: synapse.to_param }, valid_session + end.to change(Synapse, :count).by(-1) end - it "redirects to the synapses list" do + it 'redirects to the synapses list' do synapse = Synapse.create! valid_attributes - delete :destroy, {:id => synapse.to_param}, valid_session + delete :destroy, { id: synapse.to_param }, valid_session expect(response).to redirect_to(synapses_url) end end - end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 15c52e16..8fefd0b2 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -18,135 +18,133 @@ require 'rails_helper' # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. -RSpec.describe TopicsController, :type => :controller do - +RSpec.describe TopicsController, type: :controller do # This should return the minimal set of attributes required to create a valid # Topic. As you add validations to Topic, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + skip('Add a hash of attributes valid for your model') + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # TopicsController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all topics as @topics" do + describe 'GET #index' do + it 'assigns all topics as @topics' do topic = Topic.create! valid_attributes get :index, {}, valid_session expect(assigns(:topics)).to eq([topic]) end end - describe "GET #show" do - it "assigns the requested topic as @topic" do + describe 'GET #show' do + it 'assigns the requested topic as @topic' do topic = Topic.create! valid_attributes - get :show, {:id => topic.to_param}, valid_session + get :show, { id: topic.to_param }, valid_session expect(assigns(:topic)).to eq(topic) end end - describe "GET #edit" do - it "assigns the requested topic as @topic" do + describe 'GET #edit' do + it 'assigns the requested topic as @topic' do topic = Topic.create! valid_attributes - get :edit, {:id => topic.to_param}, valid_session + get :edit, { id: topic.to_param }, valid_session expect(assigns(:topic)).to eq(topic) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Topic" do - expect { - post :create, {:topic => valid_attributes}, valid_session - }.to change(Topic, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Topic' do + expect do + post :create, { topic: valid_attributes }, valid_session + end.to change(Topic, :count).by(1) end - it "assigns a newly created topic as @topic" do - post :create, {:topic => valid_attributes}, valid_session + it 'assigns a newly created topic as @topic' do + post :create, { topic: valid_attributes }, valid_session expect(assigns(:topic)).to be_a(Topic) expect(assigns(:topic)).to be_persisted end - it "redirects to the created topic" do - post :create, {:topic => valid_attributes}, valid_session + it 'redirects to the created topic' do + post :create, { topic: valid_attributes }, valid_session expect(response).to redirect_to(Topic.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved topic as @topic" do - post :create, {:topic => invalid_attributes}, valid_session + context 'with invalid params' do + it 'assigns a newly created but unsaved topic as @topic' do + post :create, { topic: invalid_attributes }, valid_session expect(assigns(:topic)).to be_a_new(Topic) end it "re-renders the 'new' template" do - post :create, {:topic => invalid_attributes}, valid_session - expect(response).to render_template("new") + post :create, { topic: invalid_attributes }, valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested topic" do - topic = Topic.create! valid_attributes - put :update, {:id => topic.to_param, :topic => new_attributes}, valid_session - topic.reload - skip("Add assertions for updated state") + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') end - it "assigns the requested topic as @topic" do + it 'updates the requested topic' do topic = Topic.create! valid_attributes - put :update, {:id => topic.to_param, :topic => valid_attributes}, valid_session + put :update, { id: topic.to_param, topic: new_attributes }, valid_session + topic.reload + skip('Add assertions for updated state') + end + + it 'assigns the requested topic as @topic' do + topic = Topic.create! valid_attributes + put :update, { id: topic.to_param, topic: valid_attributes }, valid_session expect(assigns(:topic)).to eq(topic) end - it "redirects to the topic" do + it 'redirects to the topic' do topic = Topic.create! valid_attributes - put :update, {:id => topic.to_param, :topic => valid_attributes}, valid_session + put :update, { id: topic.to_param, topic: valid_attributes }, valid_session expect(response).to redirect_to(topic) end end - context "with invalid params" do - it "assigns the topic as @topic" do + context 'with invalid params' do + it 'assigns the topic as @topic' do topic = Topic.create! valid_attributes - put :update, {:id => topic.to_param, :topic => invalid_attributes}, valid_session + put :update, { id: topic.to_param, topic: invalid_attributes }, valid_session expect(assigns(:topic)).to eq(topic) end it "re-renders the 'edit' template" do topic = Topic.create! valid_attributes - put :update, {:id => topic.to_param, :topic => invalid_attributes}, valid_session - expect(response).to render_template("edit") + put :update, { id: topic.to_param, topic: invalid_attributes }, valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested topic" do + describe 'DELETE #destroy' do + it 'destroys the requested topic' do topic = Topic.create! valid_attributes - expect { - delete :destroy, {:id => topic.to_param}, valid_session - }.to change(Topic, :count).by(-1) + expect do + delete :destroy, { id: topic.to_param }, valid_session + end.to change(Topic, :count).by(-1) end - it "redirects to the topics list" do + it 'redirects to the topics list' do topic = Topic.create! valid_attributes - delete :destroy, {:id => topic.to_param}, valid_session + delete :destroy, { id: topic.to_param }, valid_session expect(response).to redirect_to(topics_url) end end - end diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb index 47ed5c04..f39a7dd6 100644 --- a/spec/factories/synapses.rb +++ b/spec/factories/synapses.rb @@ -2,8 +2,8 @@ FactoryGirl.define do factory :synapse do desc { random_string(10) } category :to - permission :commons - association :node1, factory: :topic + permission :commons + association :node1, factory: :topic association :node2, factory: :topic end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 48edb0c1..c645aa6b 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -5,6 +5,6 @@ FactoryGirl.define do code { random_string(8) } joinedwithcode { code } password 'omgwtfbbq' - to_create {|instance| instance.save(validate: false) } # bypass validation of the joinedwithcode + to_create { |instance| instance.save(validate: false) } # bypass validation of the joinedwithcode end end diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index dc475ba3..8a83947e 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Map, :type => :model do +RSpec.describe Map, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb index e00c5074..32d34796 100644 --- a/spec/models/mapping_spec.rb +++ b/spec/models/mapping_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Mapping, :type => :model do +RSpec.describe Mapping, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb index a548118a..de0e79a1 100644 --- a/spec/models/metacode_spec.rb +++ b/spec/models/metacode_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Metacode, :type => :model do +RSpec.describe Metacode, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index d1faf2c8..dd03e0a0 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Synapse, :type => :model do +RSpec.describe Synapse, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index a52bb072..b8c5a8e0 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Topic, :type => :model do +RSpec.describe Topic, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f6d8fd0b..c109fae8 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,7 +2,7 @@ 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? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'spec_helper' require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! diff --git a/spec/routing/mappings_routing_spec.rb b/spec/routing/mappings_routing_spec.rb index d8266398..6b6d75dc 100644 --- a/spec/routing/mappings_routing_spec.rb +++ b/spec/routing/mappings_routing_spec.rb @@ -1,23 +1,21 @@ -require "rails_helper" +require 'rails_helper' -RSpec.describe MappingsController, :type => :routing do - describe "routing" do - - it "routes to #show" do - expect(:get => "/mappings/1").to route_to("mappings#show", :id => "1") +RSpec.describe MappingsController, type: :routing do + describe 'routing' do + it 'routes to #show' do + expect(get: '/mappings/1').to route_to('mappings#show', id: '1') end - it "routes to #create" do - expect(:post => "/mappings").to route_to("mappings#create") + it 'routes to #create' do + expect(post: '/mappings').to route_to('mappings#create') end - it "routes to #update via PUT" do - expect(:put => "/mappings/1").to route_to("mappings#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/mappings/1').to route_to('mappings#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/mappings/1").to route_to("mappings#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/mappings/1').to route_to('mappings#destroy', id: '1') end - end end diff --git a/spec/routing/maps_routing_spec.rb b/spec/routing/maps_routing_spec.rb index 1e77be48..9d0dcaee 100644 --- a/spec/routing/maps_routing_spec.rb +++ b/spec/routing/maps_routing_spec.rb @@ -1,27 +1,25 @@ -require "rails_helper" +require 'rails_helper' -RSpec.describe MapsController, :type => :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/maps").to route_to("maps#index") +RSpec.describe MapsController, type: :routing do + describe 'routing' do + it 'routes to #index' do + expect(get: '/maps').to route_to('maps#index') end - it "routes to #show" do - expect(:get => "/maps/1").to route_to("maps#show", :id => "1") + it 'routes to #show' do + expect(get: '/maps/1').to route_to('maps#show', id: '1') end - it "routes to #create" do - expect(:post => "/maps").to route_to("maps#create") + it 'routes to #create' do + expect(post: '/maps').to route_to('maps#create') end - it "routes to #update via PUT" do - expect(:put => "/maps/1").to route_to("maps#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/maps/1').to route_to('maps#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/maps/1").to route_to("maps#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/maps/1').to route_to('maps#destroy', id: '1') end - end end diff --git a/spec/routing/metacodes_routing_spec.rb b/spec/routing/metacodes_routing_spec.rb index 2bc39be7..1f129448 100644 --- a/spec/routing/metacodes_routing_spec.rb +++ b/spec/routing/metacodes_routing_spec.rb @@ -1,30 +1,29 @@ -require "rails_helper" +require 'rails_helper' -RSpec.describe MetacodesController, :type => :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/metacodes").to route_to("metacodes#index") +RSpec.describe MetacodesController, type: :routing do + describe 'routing' do + it 'routes to #index' do + expect(get: '/metacodes').to route_to('metacodes#index') end - it "routes to #new" do - expect(:get => "/metacodes/new").to route_to("metacodes#new") + it 'routes to #new' do + expect(get: '/metacodes/new').to route_to('metacodes#new') end - it "routes to #edit" do - expect(:get => "/metacodes/1/edit").to route_to("metacodes#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/metacodes/1/edit').to route_to('metacodes#edit', id: '1') end - it "routes to #create" do - expect(:post => "/metacodes").to route_to("metacodes#create") + it 'routes to #create' do + expect(post: '/metacodes').to route_to('metacodes#create') end - it "routes to #update via PUT" do - expect(:put => "/metacodes/1").to route_to("metacodes#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/metacodes/1').to route_to('metacodes#update', id: '1') end - #it "routes to #destroy" do + # it "routes to #destroy" do # expect(:delete => "/metacodes/1").to route_to("metacodes#destroy", :id => "1") - #end + # end end end diff --git a/spec/routing/synapses_routing_spec.rb b/spec/routing/synapses_routing_spec.rb index e0639bd0..4fd4861f 100644 --- a/spec/routing/synapses_routing_spec.rb +++ b/spec/routing/synapses_routing_spec.rb @@ -1,23 +1,21 @@ -require "rails_helper" +require 'rails_helper' -RSpec.describe SynapsesController, :type => :routing do - describe "routing" do - - it "routes to #show" do - expect(:get => "/synapses/1").to route_to("synapses#show", :id => "1") +RSpec.describe SynapsesController, type: :routing do + describe 'routing' do + it 'routes to #show' do + expect(get: '/synapses/1').to route_to('synapses#show', id: '1') end - it "routes to #create" do - expect(:post => "/synapses").to route_to("synapses#create") + it 'routes to #create' do + expect(post: '/synapses').to route_to('synapses#create') end - it "routes to #update via PUT" do - expect(:put => "/synapses/1").to route_to("synapses#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/synapses/1').to route_to('synapses#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/synapses/1").to route_to("synapses#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/synapses/1').to route_to('synapses#destroy', id: '1') end - end end diff --git a/spec/routing/topics_routing_spec.rb b/spec/routing/topics_routing_spec.rb index 515e15bf..66778404 100644 --- a/spec/routing/topics_routing_spec.rb +++ b/spec/routing/topics_routing_spec.rb @@ -1,23 +1,21 @@ -require "rails_helper" +require 'rails_helper' -RSpec.describe TopicsController, :type => :routing do - describe "routing" do - - it "routes to #show" do - expect(:get => "/topics/1").to route_to("topics#show", :id => "1") +RSpec.describe TopicsController, type: :routing do + describe 'routing' do + it 'routes to #show' do + expect(get: '/topics/1').to route_to('topics#show', id: '1') end - it "routes to #create" do - expect(:post => "/topics").to route_to("topics#create") + it 'routes to #create' do + expect(post: '/topics').to route_to('topics#create') end - it "routes to #update via PUT" do - expect(:put => "/topics/1").to route_to("topics#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/topics/1').to route_to('topics#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/topics/1").to route_to("topics#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/topics/1').to route_to('topics#destroy', id: '1') end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be9f0d88..c72432be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,58 +41,56 @@ RSpec.configure do |config| mocks.verify_partial_doubles = true end -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # These two settings work together to allow 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. - config.filter_run :focus - config.run_all_when_everything_filtered = true - - # 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://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching - 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 + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # These two settings work together to allow 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. + # config.filter_run :focus + # config.run_all_when_everything_filtered = true + # + # # 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://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + # 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 def random_string(length = 10) - o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten + o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten string = (0...length).map { o[rand(o.length)] }.join end diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index e8435ba7..b148ff6e 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -3,7 +3,7 @@ module ControllerHelpers def sign_in(user = create(:user)) if user.nil? # simulate unauthenticated - allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user}) + allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, scope: :user) allow(controller).to receive(:current_user).and_return(nil) else # simulate authenticated diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb index de2a780d..afae617a 100644 --- a/spec/support/factory_girl.rb +++ b/spec/support/factory_girl.rb @@ -1,4 +1,4 @@ # lets you type create(:user) instead of FactoryGirl.create(:user) RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods + config.include FactoryGirl::Syntax::Methods end From a93473f2c9a7ab8e210d09c4993ee9e2716e3397 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 22:33:29 +0800 Subject: [PATCH 15/44] rubocop spec folder --- spec/controllers/mappings_controller_spec.rb | 20 +++-- spec/controllers/maps_controller_spec.rb | 20 +++-- spec/controllers/metacodes_controller_spec.rb | 20 +++-- spec/controllers/synapses_controller_spec.rb | 20 +++-- spec/controllers/topics_controller_spec.rb | 44 ++++------ spec/factories/users.rb | 4 +- spec/rails_helper.rb | 6 +- spec/routing/metacodes_routing_spec.rb | 4 - spec/spec_helper.rb | 87 ++----------------- spec/support/controller_helpers.rb | 19 ++-- 10 files changed, 99 insertions(+), 145 deletions(-) diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index 1fc3e181..8a7acda5 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -100,20 +100,26 @@ RSpec.describe MappingsController, type: :controller do it 'updates the requested mapping' do mapping = Mapping.create! valid_attributes - put :update, { id: mapping.to_param, mapping: new_attributes }, valid_session + put :update, + { id: mapping.to_param, mapping: new_attributes }, + valid_session mapping.reload skip('Add assertions for updated state') end it 'assigns the requested mapping as @mapping' do mapping = Mapping.create! valid_attributes - put :update, { id: mapping.to_param, mapping: valid_attributes }, valid_session + put :update, + { id: mapping.to_param, mapping: valid_attributes }, + valid_session expect(assigns(:mapping)).to eq(mapping) end it 'redirects to the mapping' do mapping = Mapping.create! valid_attributes - put :update, { id: mapping.to_param, mapping: valid_attributes }, valid_session + put :update, + { id: mapping.to_param, mapping: valid_attributes }, + valid_session expect(response).to redirect_to(mapping) end end @@ -121,13 +127,17 @@ RSpec.describe MappingsController, type: :controller do context 'with invalid params' do it 'assigns the mapping as @mapping' do mapping = Mapping.create! valid_attributes - put :update, { id: mapping.to_param, mapping: invalid_attributes }, valid_session + put :update, + { id: mapping.to_param, mapping: invalid_attributes }, + valid_session expect(assigns(:mapping)).to eq(mapping) end it "re-renders the 'edit' template" do mapping = Mapping.create! valid_attributes - put :update, { id: mapping.to_param, mapping: invalid_attributes }, valid_session + put :update, + { id: mapping.to_param, mapping: invalid_attributes }, + valid_session expect(response).to render_template('edit') end end diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index ff16c87b..fdaa064a 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -100,20 +100,26 @@ RSpec.describe MapsController, type: :controller do it 'updates the requested map' do map = Map.create! valid_attributes - put :update, { id: map.to_param, map: new_attributes }, valid_session + put :update, + { id: map.to_param, map: new_attributes }, + valid_session map.reload skip('Add assertions for updated state') end it 'assigns the requested map as @map' do map = Map.create! valid_attributes - put :update, { id: map.to_param, map: valid_attributes }, valid_session + put :update, + { id: map.to_param, map: valid_attributes }, + valid_session expect(assigns(:map)).to eq(map) end it 'redirects to the map' do map = Map.create! valid_attributes - put :update, { id: map.to_param, map: valid_attributes }, valid_session + put :update, + { id: map.to_param, map: valid_attributes }, + valid_session expect(response).to redirect_to(map) end end @@ -121,13 +127,17 @@ RSpec.describe MapsController, type: :controller do context 'with invalid params' do it 'assigns the map as @map' do map = Map.create! valid_attributes - put :update, { id: map.to_param, map: invalid_attributes }, valid_session + put :update, + { id: map.to_param, map: invalid_attributes }, + valid_session expect(assigns(:map)).to eq(map) end it "re-renders the 'edit' template" do map = Map.create! valid_attributes - put :update, { id: map.to_param, map: invalid_attributes }, valid_session + put :update, + { id: map.to_param, map: invalid_attributes }, + valid_session expect(response).to render_template('edit') end end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index 6f307cb6..6e1ba2b9 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -112,20 +112,26 @@ RSpec.describe MetacodesController, type: :controller do it 'updates the requested metacode' do metacode = Metacode.create! valid_attributes - put :update, { id: metacode.to_param, metacode: new_attributes }, valid_session + put :update, + { id: metacode.to_param, metacode: new_attributes }, + valid_session metacode.reload skip('Add assertions for updated state') end it 'assigns the requested metacode as @metacode' do metacode = Metacode.create! valid_attributes - put :update, { id: metacode.to_param, metacode: valid_attributes }, valid_session + put :update, + { id: metacode.to_param, metacode: valid_attributes }, + valid_session expect(assigns(:metacode)).to eq(metacode) end it 'redirects to the metacode' do metacode = Metacode.create! valid_attributes - put :update, { id: metacode.to_param, metacode: valid_attributes }, valid_session + put :update, + { id: metacode.to_param, metacode: valid_attributes }, + valid_session expect(response).to redirect_to(metacode) end end @@ -133,13 +139,17 @@ RSpec.describe MetacodesController, type: :controller do context 'with invalid params' do it 'assigns the metacode as @metacode' do metacode = Metacode.create! valid_attributes - put :update, { id: metacode.to_param, metacode: invalid_attributes }, valid_session + put :update, + { id: metacode.to_param, metacode: invalid_attributes }, + valid_session expect(assigns(:metacode)).to eq(metacode) end it "re-renders the 'edit' template" do metacode = Metacode.create! valid_attributes - put :update, { id: metacode.to_param, metacode: invalid_attributes }, valid_session + put :update, + { id: metacode.to_param, metacode: invalid_attributes }, + valid_session expect(response).to render_template('edit') end end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 62f9c6ac..ff05ea6f 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -100,20 +100,26 @@ RSpec.describe SynapsesController, type: :controller do it 'updates the requested synapse' do synapse = Synapse.create! valid_attributes - put :update, { id: synapse.to_param, synapse: new_attributes }, valid_session + put :update, + { id: synapse.to_param, synapse: new_attributes }, + valid_session synapse.reload skip('Add assertions for updated state') end it 'assigns the requested synapse as @synapse' do synapse = Synapse.create! valid_attributes - put :update, { id: synapse.to_param, synapse: valid_attributes }, valid_session + put :update, + { id: synapse.to_param, synapse: valid_attributes }, + valid_session expect(assigns(:synapse)).to eq(synapse) end it 'redirects to the synapse' do synapse = Synapse.create! valid_attributes - put :update, { id: synapse.to_param, synapse: valid_attributes }, valid_session + put :update, + { id: synapse.to_param, synapse: valid_attributes }, + valid_session expect(response).to redirect_to(synapse) end end @@ -121,13 +127,17 @@ RSpec.describe SynapsesController, type: :controller do context 'with invalid params' do it 'assigns the synapse as @synapse' do synapse = Synapse.create! valid_attributes - put :update, { id: synapse.to_param, synapse: invalid_attributes }, valid_session + put :update, + { id: synapse.to_param, synapse: invalid_attributes }, + valid_session expect(assigns(:synapse)).to eq(synapse) end it "re-renders the 'edit' template" do synapse = Synapse.create! valid_attributes - put :update, { id: synapse.to_param, synapse: invalid_attributes }, valid_session + put :update, + { id: synapse.to_param, synapse: invalid_attributes }, + valid_session expect(response).to render_template('edit') end end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 8fefd0b2..35b2156e 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -1,27 +1,6 @@ require 'rails_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - RSpec.describe TopicsController, type: :controller do - # This should return the minimal set of attributes required to create a valid - # Topic. As you add validations to Topic, be sure to - # adjust the attributes here as well. let(:valid_attributes) do skip('Add a hash of attributes valid for your model') end @@ -30,9 +9,6 @@ RSpec.describe TopicsController, type: :controller do skip('Add a hash of attributes invalid for your model') end - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # TopicsController. Be sure to keep this updated too. let(:valid_session) { {} } describe 'GET #index' do @@ -100,20 +76,26 @@ RSpec.describe TopicsController, type: :controller do it 'updates the requested topic' do topic = Topic.create! valid_attributes - put :update, { id: topic.to_param, topic: new_attributes }, valid_session + put :update, + { id: topic.to_param, topic: new_attributes }, + valid_session topic.reload skip('Add assertions for updated state') end it 'assigns the requested topic as @topic' do topic = Topic.create! valid_attributes - put :update, { id: topic.to_param, topic: valid_attributes }, valid_session + put :update, + { id: topic.to_param, topic: valid_attributes }, + valid_session expect(assigns(:topic)).to eq(topic) end it 'redirects to the topic' do topic = Topic.create! valid_attributes - put :update, { id: topic.to_param, topic: valid_attributes }, valid_session + put :update, + { id: topic.to_param, topic: valid_attributes }, + valid_session expect(response).to redirect_to(topic) end end @@ -121,13 +103,17 @@ RSpec.describe TopicsController, type: :controller do context 'with invalid params' do it 'assigns the topic as @topic' do topic = Topic.create! valid_attributes - put :update, { id: topic.to_param, topic: invalid_attributes }, valid_session + put :update, + { id: topic.to_param, topic: invalid_attributes }, + valid_session expect(assigns(:topic)).to eq(topic) end it "re-renders the 'edit' template" do topic = Topic.create! valid_attributes - put :update, { id: topic.to_param, topic: invalid_attributes }, valid_session + put :update, + { id: topic.to_param, topic: invalid_attributes }, + valid_session expect(response).to render_template('edit') end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index c645aa6b..8bdcb17e 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -5,6 +5,8 @@ FactoryGirl.define do code { random_string(8) } joinedwithcode { code } password 'omgwtfbbq' - to_create { |instance| instance.save(validate: false) } # bypass validation of the joinedwithcode + + # bypass validation of the joinedwithcode + to_create { |instance| instance.save(validate: false) } end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c109fae8..17c04cd7 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,8 +1,12 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' 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? +if Rails.env.production? + abort('The Rails environment is running in production mode!') +end + require 'spec_helper' require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! diff --git a/spec/routing/metacodes_routing_spec.rb b/spec/routing/metacodes_routing_spec.rb index 1f129448..151148fe 100644 --- a/spec/routing/metacodes_routing_spec.rb +++ b/spec/routing/metacodes_routing_spec.rb @@ -21,9 +21,5 @@ RSpec.describe MetacodesController, type: :routing do it 'routes to #update via PUT' do expect(put: '/metacodes/1').to route_to('metacodes#update', id: '1') end - - # it "routes to #destroy" do - # expect(:delete => "/metacodes/1").to route_to("metacodes#destroy", :id => "1") - # end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c72432be..14cfd1c7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,96 +1,19 @@ -# 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. -# -# The `.rspec` file also contains a few flags that are not defaults but that -# users commonly want. -# -# 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 - # The settings below are suggested to provide a good initial experience - # with RSpec, but feel free to customize to your heart's content. - # # These two settings work together to allow 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. - # config.filter_run :focus - # config.run_all_when_everything_filtered = true - # - # # 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://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching - # 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 + # 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 end def random_string(length = 10) o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten - string = (0...length).map { o[rand(o.length)] }.join + (0...length).map { o[rand(o.length)] }.join end diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index b148ff6e..5fe34854 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -1,14 +1,17 @@ # https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs module ControllerHelpers + # rubocop:disable Metrics/AbcSize def sign_in(user = create(:user)) - if user.nil? - # simulate unauthenticated - allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, scope: :user) - allow(controller).to receive(:current_user).and_return(nil) - else - # simulate authenticated - allow(request.env['warden']).to receive(:authenticate!).and_return(user) - allow(controller).to receive(:current_user).and_return(user) + if user.nil? # simulate unauthenticated + allow(request.env['warden']).to( + receive(:authenticate!).and_throw(:warden, scope: :user) + ) + else # simulate authenticated + allow(request.env['warden']).to( + receive(:authenticate!).and_return(user) + ) end + allow(controller).to receive(:current_user).and_return(user) end + # rubocop:enable Metrics/AbcSize end From 4dbff85443c845c9a8a18a0c32d0bda824ebc93d Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 22:36:12 +0800 Subject: [PATCH 16/44] default value if no request.env in application controller passes the rspec test woot. Only 80 more tests to implement --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6a79915c..89b6fa09 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -58,9 +58,9 @@ private end def get_invite_link - unsafe_uri = request.env["REQUEST_URI"] + unsafe_uri = request.env["REQUEST_URI"] || 'http://metamaps.cc' valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ - safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : "http://metamaps.cc/" + safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : 'http://metamaps.cc/' @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") end end From 1ff235f547925faadb728f1e1483caf57ed3f1fd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 16 Dec 2015 22:36:41 +0800 Subject: [PATCH 17/44] who needs routing specs bah --- spec/routing/mappings_routing_spec.rb | 21 --------------------- spec/routing/maps_routing_spec.rb | 25 ------------------------- spec/routing/metacodes_routing_spec.rb | 25 ------------------------- spec/routing/synapses_routing_spec.rb | 21 --------------------- spec/routing/topics_routing_spec.rb | 21 --------------------- 5 files changed, 113 deletions(-) delete mode 100644 spec/routing/mappings_routing_spec.rb delete mode 100644 spec/routing/maps_routing_spec.rb delete mode 100644 spec/routing/metacodes_routing_spec.rb delete mode 100644 spec/routing/synapses_routing_spec.rb delete mode 100644 spec/routing/topics_routing_spec.rb diff --git a/spec/routing/mappings_routing_spec.rb b/spec/routing/mappings_routing_spec.rb deleted file mode 100644 index 6b6d75dc..00000000 --- a/spec/routing/mappings_routing_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe MappingsController, type: :routing do - describe 'routing' do - it 'routes to #show' do - expect(get: '/mappings/1').to route_to('mappings#show', id: '1') - end - - it 'routes to #create' do - expect(post: '/mappings').to route_to('mappings#create') - end - - it 'routes to #update via PUT' do - expect(put: '/mappings/1').to route_to('mappings#update', id: '1') - end - - it 'routes to #destroy' do - expect(delete: '/mappings/1').to route_to('mappings#destroy', id: '1') - end - end -end diff --git a/spec/routing/maps_routing_spec.rb b/spec/routing/maps_routing_spec.rb deleted file mode 100644 index 9d0dcaee..00000000 --- a/spec/routing/maps_routing_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -RSpec.describe MapsController, type: :routing do - describe 'routing' do - it 'routes to #index' do - expect(get: '/maps').to route_to('maps#index') - end - - it 'routes to #show' do - expect(get: '/maps/1').to route_to('maps#show', id: '1') - end - - it 'routes to #create' do - expect(post: '/maps').to route_to('maps#create') - end - - it 'routes to #update via PUT' do - expect(put: '/maps/1').to route_to('maps#update', id: '1') - end - - it 'routes to #destroy' do - expect(delete: '/maps/1').to route_to('maps#destroy', id: '1') - end - end -end diff --git a/spec/routing/metacodes_routing_spec.rb b/spec/routing/metacodes_routing_spec.rb deleted file mode 100644 index 151148fe..00000000 --- a/spec/routing/metacodes_routing_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -RSpec.describe MetacodesController, type: :routing do - describe 'routing' do - it 'routes to #index' do - expect(get: '/metacodes').to route_to('metacodes#index') - end - - it 'routes to #new' do - expect(get: '/metacodes/new').to route_to('metacodes#new') - end - - it 'routes to #edit' do - expect(get: '/metacodes/1/edit').to route_to('metacodes#edit', id: '1') - end - - it 'routes to #create' do - expect(post: '/metacodes').to route_to('metacodes#create') - end - - it 'routes to #update via PUT' do - expect(put: '/metacodes/1').to route_to('metacodes#update', id: '1') - end - end -end diff --git a/spec/routing/synapses_routing_spec.rb b/spec/routing/synapses_routing_spec.rb deleted file mode 100644 index 4fd4861f..00000000 --- a/spec/routing/synapses_routing_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe SynapsesController, type: :routing do - describe 'routing' do - it 'routes to #show' do - expect(get: '/synapses/1').to route_to('synapses#show', id: '1') - end - - it 'routes to #create' do - expect(post: '/synapses').to route_to('synapses#create') - end - - it 'routes to #update via PUT' do - expect(put: '/synapses/1').to route_to('synapses#update', id: '1') - end - - it 'routes to #destroy' do - expect(delete: '/synapses/1').to route_to('synapses#destroy', id: '1') - end - end -end diff --git a/spec/routing/topics_routing_spec.rb b/spec/routing/topics_routing_spec.rb deleted file mode 100644 index 66778404..00000000 --- a/spec/routing/topics_routing_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe TopicsController, type: :routing do - describe 'routing' do - it 'routes to #show' do - expect(get: '/topics/1').to route_to('topics#show', id: '1') - end - - it 'routes to #create' do - expect(post: '/topics').to route_to('topics#create') - end - - it 'routes to #update via PUT' do - expect(put: '/topics/1').to route_to('topics#update', id: '1') - end - - it 'routes to #destroy' do - expect(delete: '/topics/1').to route_to('topics#destroy', id: '1') - end - end -end From b3ba6d3a8038d68620fbbfc6534607015c06596c Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 08:53:45 +0800 Subject: [PATCH 18/44] add shoulda-matchers gem --- Gemfile | 1 + Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index 4f4b0d73..b4e3bdf6 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ end group :test do gem 'rspec-rails' gem 'factory_girl_rails' + gem 'shoulda-matchers' end group :production do #this is used on heroku diff --git a/Gemfile.lock b/Gemfile.lock index 27e9e40f..5525a8cc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -201,6 +201,8 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + shoulda-matchers (3.0.1) + activesupport (>= 4.0.0) slop (3.6.0) sprockets (3.4.0) rack (> 1, < 3) @@ -255,6 +257,7 @@ DEPENDENCIES redis rspec-rails sass-rails + shoulda-matchers tunemygc uglifier uservoice-ruby From bfd4e4f228b6528c17bba48f6d4529d11c160bb9 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 09:03:51 +0800 Subject: [PATCH 19/44] add permission service, add validations to map.rb --- app/models/map.rb | 11 ++++------- app/services/perm.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 app/services/perm.rb diff --git a/app/models/map.rb b/app/models/map.rb index e6a10605..e45db636 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -13,6 +13,9 @@ class Map < ActiveRecord::Base #:full => ['940x630#', :png] }, :default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png' + validates_presence_of :name + validates_presence_of :arranged + validate_presence_of :permission # Validate the attached image is image/jpg, image/png, etc validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/ @@ -22,13 +25,7 @@ class Map < ActiveRecord::Base end def mk_permission - if self.permission == "commons" - "co" - elsif self.permission == "public" - "pu" - elsif self.permission == "private" - "pr" - end + Perm.short(permission) end #return an array of the contributors to the map diff --git a/app/services/perm.rb b/app/services/perm.rb new file mode 100644 index 00000000..7bded989 --- /dev/null +++ b/app/services/perm.rb @@ -0,0 +1,36 @@ +class Perm + class << self + # e.g. Perm::ISSIONS + ISSIONS = [:commons, :public, :private] + + def short(permission) + case permission + when :commons + "co" + when :public + "pu" + when :private + "pr" + else + fail "Invalid permission" + end + end + + def long(perm) + case perm + when "co" + :commons + when "pu" + :public + when "pr" + :private + else + fail "Invalid short permission" + end + end + + def valid?(permission) + ISSIONS.include? permission + end + end +end From 2525a6fb656d0c6dc17dd8a4402e00c44cff6412 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 09:10:52 +0800 Subject: [PATCH 20/44] add permission service, refactor map model a bit, add validations --- app/models/map.rb | 8 +++++--- app/services/perm.rb | 5 +++-- config/application.rb | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index e45db636..e5c483f1 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -13,9 +13,11 @@ class Map < ActiveRecord::Base #:full => ['940x630#', :png] }, :default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png' - validates_presence_of :name - validates_presence_of :arranged - validate_presence_of :permission + validates :name, presence: true + validates :arranged, presence: true + validates :arranged, inclusion: { in: [true, false] } + validates :permission, presence: true + validates :permission, inclusion: { in: Perm::ISSIONS } # Validate the attached image is image/jpg, image/png, etc validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/ diff --git a/app/services/perm.rb b/app/services/perm.rb index 7bded989..c18c26b7 100644 --- a/app/services/perm.rb +++ b/app/services/perm.rb @@ -1,7 +1,8 @@ class Perm + # e.g. Perm::ISSIONS + ISSIONS = [:commons, :public, :private] + class << self - # e.g. Perm::ISSIONS - ISSIONS = [:commons, :public, :private] def short(permission) case permission diff --git a/config/application.rb b/config/application.rb index dc13c79d..93bdb8bf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,7 +11,7 @@ module Metamaps # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. - # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths << Rails.root.join('app', 'services') # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. From 696bac17e6f4adb5b657eb98e86a0f5405daede7 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 09:16:02 +0800 Subject: [PATCH 21/44] map spec --- app/models/map.rb | 2 +- spec/factories/maps.rb | 7 +++++++ spec/models/map_spec.rb | 8 +++++++- spec/rails_helper.rb | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 spec/factories/maps.rb diff --git a/app/models/map.rb b/app/models/map.rb index e5c483f1..48dcae3b 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -17,7 +17,7 @@ class Map < ActiveRecord::Base validates :arranged, presence: true validates :arranged, inclusion: { in: [true, false] } validates :permission, presence: true - validates :permission, inclusion: { in: Perm::ISSIONS } + validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } # Validate the attached image is image/jpg, image/png, etc validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/ diff --git a/spec/factories/maps.rb b/spec/factories/maps.rb new file mode 100644 index 00000000..74058605 --- /dev/null +++ b/spec/factories/maps.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :map do + name { random_string(10) } + permission :commons + user + end +end diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 8a83947e..b0590edb 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -1,5 +1,11 @@ require 'rails_helper' RSpec.describe Map, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + # TODO: what is it important to be sure about when working with a Map? + it { is_expected.to belong_to :user } + it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_presence_of :arranged } + it { is_expected.to validate_presence_of :permission } + it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } end + diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 17c04cd7..23f21101 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -40,4 +40,6 @@ RSpec.configure do |config| config.include Devise::TestHelpers, type: :controller config.include ControllerHelpers, type: :controller + config.include Shoulda::Matchers::ActiveModel, type: :model + config.include Shoulda::Matchers::ActiveRecord, type: :model end From 86b79c1e55729a03ae47b05b01748b38d869bcbf Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 09:34:34 +0800 Subject: [PATCH 22/44] add brief testing docs --- doc/RspecTesting.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 doc/RspecTesting.md diff --git a/doc/RspecTesting.md b/doc/RspecTesting.md new file mode 100644 index 00000000..5da5ec88 --- /dev/null +++ b/doc/RspecTesting.md @@ -0,0 +1,27 @@ +## Testing with RSpec + +RSpec is a ruby gem that allows you to test your code base. This is great - every time you make a change, you can do some basic sanity checks to make sure you didn't break anything. + +To test Metamaps, run `rspec` in the top level directory. It will automatically search the `spec` directory for files called `*_spec.rb`, and run them as tests. When it's done testing, it will print a report telling you how many tests failed. With luck, the number will be 0. + +At the time of writing, there are four directories in the spec folder. One, `support`, is for helper functions. `rails_helper.rb` and `spec_helper.rb` are also for helper functions. + +`factories` is for a gem called [factory-girl][factory-girl]. This gem lets you use the `create` and `build` functions to quickly create the simplest possible valid version of a given model. For instance: + + let(:map1) { create :map } + let(:ronald) { create :user, name: "Ronald" } + let(:map2) { create :map, user: ronald } + +As you can see, you can also customize the factories. You can read the full documentation at the link above or check the existing specs to see how it works. It is worth reading through the factories to see how they are defined. If you add a model, please create a factory for it that defines the minimum valid state for that model. + +Finally, `models` and `controllers` have the actual spec files. Writing specs is usually fairly simple but you do need to understand the syntax. You can read more at [rspec.info][rspec-docs]. + +If you modify the metamaps codebase, please consider adding tests. This will help in a few ways: + + - Unrelated changes in the future that break your code will be spotted earlier + - Your changes will be more easily understood, since the *purpose* will be described by the spec + +Happy testing! + +[factory-girl]: https://github.com/thoughtbot/factory_girl +[rspec-docs]: http://rspec.info From 9e4a7b821fef94f4561bc99bc23bdabe12090411 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 09:34:49 +0800 Subject: [PATCH 23/44] cleanup topic model a bit --- app/models/topic.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index f82bc256..8bac9606 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -39,27 +39,27 @@ class Topic < ActiveRecord::Base belongs_to :metacode def user_name - self.user.name + user.name end def user_image - self.user.image.url + user.image.url end def map_count - self.maps.count + maps.count end def synapse_count - self.synapses.count + synapses.count end def inmaps - self.maps.map(&:name) + maps.map(&:name) end def inmapsLinks - self.maps.map(&:id) + maps.map(&:id) end def as_json(options={}) @@ -71,24 +71,18 @@ class Topic < ActiveRecord::Base end def mk_permission - if self.permission == "commons" - "co" - elsif self.permission == "public" - "pu" - elsif self.permission == "private" - "pr" - end + Perm.short(permission) end # has no viewable synapses helper function def has_viewable_synapses(current) result = false - self.synapses.each do |synapse| + synapses.each do |synapse| if synapse.authorize_to_view(current) result = true end end - return result + result end ##### PERMISSIONS ###### From d5f66487b7008acb7e4daba77cacfaa89791c9a9 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 09:44:48 +0800 Subject: [PATCH 24/44] update map spec - add authorize_to_delete. TODO: add other map authorize specs --- app/models/map.rb | 1 - spec/factories/maps.rb | 1 + spec/models/map_spec.rb | 13 ++++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index 48dcae3b..8bca3b30 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -14,7 +14,6 @@ class Map < ActiveRecord::Base }, :default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png' validates :name, presence: true - validates :arranged, presence: true validates :arranged, inclusion: { in: [true, false] } validates :permission, presence: true validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } diff --git a/spec/factories/maps.rb b/spec/factories/maps.rb index 74058605..bfda5a9a 100644 --- a/spec/factories/maps.rb +++ b/spec/factories/maps.rb @@ -2,6 +2,7 @@ FactoryGirl.define do factory :map do name { random_string(10) } permission :commons + arranged { false } user end end diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index b0590edb..688c4252 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -4,8 +4,19 @@ RSpec.describe Map, type: :model do # TODO: what is it important to be sure about when working with a Map? it { is_expected.to belong_to :user } it { is_expected.to validate_presence_of :name } - it { is_expected.to validate_presence_of :arranged } it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } + it { is_expected.to validate_inclusion_of(:arranged).in_array [true, false] } + + context 'permissions' do + let(:owner) { create :user } + let(:other_user) { create :user } + let(:map) { create :map, user: owner, permission: :commons } + + it 'prevents deletion by non-owner' do + expect(map.authorize_to_delete(other_user)).to eq false + expect(map.authorize_to_delete(owner)).to eq map + end + end end From 006acac6b55a2f187eba9a9dbab053ba2593d196 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 23:20:19 +0800 Subject: [PATCH 25/44] remove redundant authorize_to_view function --- app/models/map.rb | 8 -------- app/models/synapse.rb | 9 --------- app/models/topic.rb | 10 +--------- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index 8bca3b30..87019d2a 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -107,14 +107,6 @@ class Map < ActiveRecord::Base end return self end - - # returns Boolean if user allowed to view Topic, Synapse, or Map - def authorize_to_view(user) - if (self.permission == "private" && self.user != user) - return false - end - return true - end def decode_base64(imgBase64) decoded_data = Base64.decode64(imgBase64) diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 2745106f..943c8635 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -48,13 +48,4 @@ class Synapse < ActiveRecord::Base end return false end - - # returns Boolean if user allowed to view Topic, Synapse, or Map - def authorize_to_view(user) - if (self.permission == "private" && self.user != user) - return false - end - return true - end - end diff --git a/app/models/topic.rb b/app/models/topic.rb index 8bac9606..6f694868 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -78,7 +78,7 @@ class Topic < ActiveRecord::Base def has_viewable_synapses(current) result = false synapses.each do |synapse| - if synapse.authorize_to_view(current) + if synapse.authorize_to_show(current) result = true end end @@ -111,12 +111,4 @@ class Topic < ActiveRecord::Base end return false end - - # returns Boolean if user allowed to view Topic, Synapse, or Map - def authorize_to_view(user) - if (self.permission == "private" && self.user != user) - return false - end - return true - end end From 9522c302737442df8530250e123ff3092006355e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 23:20:53 +0800 Subject: [PATCH 26/44] finish map spec permissions --- spec/models/map_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 688c4252..f12aa9e0 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -12,11 +12,29 @@ RSpec.describe Map, type: :model do let(:owner) { create :user } let(:other_user) { create :user } let(:map) { create :map, user: owner, permission: :commons } + let(:private_map) { create :map, user: owner, permission: :private } + let(:public_map) { create :map, user: owner, permission: :public } it 'prevents deletion by non-owner' do expect(map.authorize_to_delete(other_user)).to eq false expect(map.authorize_to_delete(owner)).to eq map end + + it 'prevents visibility if private' do + expect(map.authorize_to_show(other_user)).to eq true + expect(map.authorize_to_show(owner)).to eq true + expect(private_map.authorize_to_show(owner)).to eq true + expect(private_map.authorize_to_show(other_user)).to eq false + end + + it 'only allows editing if commons or owned' do + expect(map.authorize_to_edit(other_user)).to eq true + expect(map.authorize_to_edit(owner)).to eq true + expect(private_map.authorize_to_edit(other_user)).to eq false + expect(private_map.authorize_to_edit(owner)).to eq true + expect(public_map.authorize_to_edit(other_user)).to eq false + expect(public_map.authorize_to_edit(owner)).to eq true + end end end From cf6411988d1f57d020ea636d87963b163e79b9e6 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 17 Dec 2015 23:45:38 +0800 Subject: [PATCH 27/44] topic spec - need to add permissions and fix 2 failing tests --- spec/factories/metacodes.rb | 4 +++ spec/factories/synapses.rb | 4 +-- spec/factories/topics.rb | 2 ++ spec/models/topic_spec.rb | 50 ++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 spec/factories/metacodes.rb diff --git a/spec/factories/metacodes.rb b/spec/factories/metacodes.rb new file mode 100644 index 00000000..5cfb38f6 --- /dev/null +++ b/spec/factories/metacodes.rb @@ -0,0 +1,4 @@ +FactoryGirl.define do + factory :metacode do + end +end diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb index f39a7dd6..10fd74da 100644 --- a/spec/factories/synapses.rb +++ b/spec/factories/synapses.rb @@ -3,7 +3,7 @@ FactoryGirl.define do desc { random_string(10) } category :to permission :commons - association :node1, factory: :topic - association :node2, factory: :topic + association :topic1, factory: :topic + association :topic2, factory: :topic end end diff --git a/spec/factories/topics.rb b/spec/factories/topics.rb index ecec31a3..c54301c1 100644 --- a/spec/factories/topics.rb +++ b/spec/factories/topics.rb @@ -2,5 +2,7 @@ FactoryGirl.define do factory :topic do name { random_string(10) } permission :commons + user + metacode end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index b8c5a8e0..17485803 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1,5 +1,53 @@ require 'rails_helper' RSpec.describe Topic, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it { is_expected.to belong_to :user } + it { is_expected.to belong_to :metacode } + it { is_expected.to have_many :maps } + + context 'has_viewable_synapses function' do + let (:user) { create(:user) } + let (:other_user) { create(:user) } + + context 'topic with no synapses' do + let (:topic) { create(:topic) } + + it 'returns false' do + expect(topic.has_viewable_synapses(user)).to eq false + end + end + + context 'topic with one unpermitted synapse' do + let (:topic) { create(:topic) } + let (:synapse) { create(:synapse, permission: :private, topic1: topic, user: other_user) } + + it 'returns false' do + expect(topic.has_viewable_synapses(user)).to eq false + end + end + + context 'topic with one permitted synapse' do + let (:topic) { create(:topic) } + let (:synapse) { create(:synapse, permission: :private, topic1: topic, user: user) } + + it 'returns true' do + expect(topic.has_viewable_synapses(user)).to eq true + end + end + + context 'topic with one unpermitted, one permitted synapse' do + let (:topic) { create(:topic) } + let (:synapse1) { create(:synapse, permission: :private, topic1: topic, user: other_user) } + let (:synapse2) { create(:synapse, permission: :private, topic1: topic, user: user) } + + it 'returns true' do + expect(topic.synapses.count).to eq 2 + expect(topic.has_viewable_synapses(user)).to eq true + end + end + end + + context 'permssions' do + pending "TODO" + end end From c4be57e525f992110fb2b72869e5304a7b41b515 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:25:54 +0800 Subject: [PATCH 28/44] topic and synapse validate permission --- app/models/synapse.rb | 3 +++ app/models/topic.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 943c8635..225485e5 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -10,6 +10,9 @@ class Synapse < ActiveRecord::Base validates :desc, length: { minimum: 0, allow_nil: false } + validates :permission, presence: true + validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } + def user_name self.user.name end diff --git a/app/models/topic.rb b/app/models/topic.rb index 6f694868..e80d3df7 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -10,6 +10,9 @@ class Topic < ActiveRecord::Base has_many :mappings, as: :mappable, dependent: :destroy has_many :maps, :through => :mappings + + validates :permission, presence: true + validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } # This method associates the attribute ":image" with a file attachment has_attached_file :image From a4c309a677a77ef73ee0b6ac87ebdba9ba1bad80 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:26:07 +0800 Subject: [PATCH 29/44] finish topic spec --- spec/models/topic_spec.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 17485803..d8ec84e8 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -4,6 +4,9 @@ RSpec.describe Topic, type: :model do it { is_expected.to belong_to :user } it { is_expected.to belong_to :metacode } it { is_expected.to have_many :maps } + it { is_expected.to have_many :mappings } + it { is_expected.to validate_presence_of :permission } + it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } context 'has_viewable_synapses function' do let (:user) { create(:user) } @@ -48,6 +51,30 @@ RSpec.describe Topic, type: :model do end context 'permssions' do - pending "TODO" + let(:other_user) { create :user } + let(:topic) { create :topic, user: owner, permission: :commons } + let(:private_topic) { create :topic, user: owner, permission: :private } + let(:public_topic) { create :topic, user: owner, permission: :public } + + it 'prevents deletion by non-owner' do + expect(topic.authorize_to_delete(other_user)).to eq false + expect(topic.authorize_to_delete(owner)).to eq topic + end + + it 'prevents visibility if private' do + expect(topic.authorize_to_show(other_user)).to eq true + expect(topic.authorize_to_show(owner)).to eq true + expect(private_topic.authorize_to_show(owner)).to eq true + expect(private_topic.authorize_to_show(other_user)).to eq false + end + + it 'only allows editing if commons or owned' do + expect(topic.authorize_to_edit(other_user)).to eq true + expect(topic.authorize_to_edit(owner)).to eq true + expect(private_topic.authorize_to_edit(other_user)).to eq false + expect(private_topic.authorize_to_edit(owner)).to eq true + expect(public_topic.authorize_to_edit(other_user)).to eq false + expect(public_topic.authorize_to_edit(owner)).to eq true + end end end From 4b22a856c34008ba3306fe53012a6e2cc6326c7f Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:26:15 +0800 Subject: [PATCH 30/44] synapse spec --- spec/models/synapse_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index dd03e0a0..2363394c 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -2,4 +2,39 @@ require 'rails_helper' RSpec.describe Synapse, type: :model do pending "add some examples to (or delete) #{__FILE__}" + pending "validate that desc can't be nil - important for javascript" + it { is_expected.to belong_to :user } + it { is_expected.to belong_to :topic1 } + it { is_expected.to belong_to :topic2 } + it { is_expected.to have_many :maps } + it { is_expected.to have_many :mappings } + + context 'permissions' do + let(:owner) { create :user } + let(:other_user) { create :user } + let(:synapse) { create :synapse, user: owner, permission: :commons } + let(:private_synapse) { create :synapse, user: owner, permission: :private } + let(:public_synapse) { create :synapse, user: owner, permission: :public } + + it 'prevents deletion by non-owner' do + expect(synapse.authorize_to_delete(other_user)).to eq false + expect(synapse.authorize_to_delete(owner)).to eq synapse + end + + it 'prevents visibility if private' do + expect(synapse.authorize_to_show(other_user)).to eq true + expect(synapse.authorize_to_show(owner)).to eq true + expect(private_synapse.authorize_to_show(owner)).to eq true + expect(private_synapse.authorize_to_show(other_user)).to eq false + end + + it 'only allows editing if commons or owned' do + expect(synapse.authorize_to_edit(other_user)).to eq true + expect(synapse.authorize_to_edit(owner)).to eq true + expect(private_synapse.authorize_to_edit(other_user)).to eq false + expect(private_synapse.authorize_to_edit(owner)).to eq true + expect(public_synapse.authorize_to_edit(other_user)).to eq false + expect(public_synapse.authorize_to_edit(owner)).to eq true + end + end end From acd048bd0df4ea2711ed1dd0ff563e369f33632e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:28:08 +0800 Subject: [PATCH 31/44] can't properly use rspec on a boolean field validation --- spec/models/map_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index f12aa9e0..ec251d53 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -6,7 +6,6 @@ RSpec.describe Map, type: :model do it { is_expected.to validate_presence_of :name } it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } - it { is_expected.to validate_inclusion_of(:arranged).in_array [true, false] } context 'permissions' do let(:owner) { create :user } From d2680fd9f374c32401e74e824e71bdd00217016f Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:28:20 +0800 Subject: [PATCH 32/44] permissions on synapse spec --- spec/models/synapse_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index 2363394c..f42427b8 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -8,6 +8,8 @@ RSpec.describe Synapse, type: :model do it { is_expected.to belong_to :topic2 } it { is_expected.to have_many :maps } it { is_expected.to have_many :mappings } + it { is_expected.to validate_presence_of :permission } + it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } context 'permissions' do let(:owner) { create :user } From ca282f7879a1e29c8c5323b4a584b5a5a974649c Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:28:28 +0800 Subject: [PATCH 33/44] topic spec owner --- spec/models/topic_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index d8ec84e8..4c4ce31d 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -51,6 +51,7 @@ RSpec.describe Topic, type: :model do end context 'permssions' do + let(:owner) { create :user } let(:other_user) { create :user } let(:topic) { create :topic, user: owner, permission: :commons } let(:private_topic) { create :topic, user: owner, permission: :private } From 6bb8ac7e1f1c7894a2e537938b9a87d47ce089aa Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:33:16 +0800 Subject: [PATCH 34/44] fix dumb errors - only 2 topic specs fail now --- spec/models/map_spec.rb | 14 +++++++------- spec/models/synapse_spec.rb | 14 +++++++------- spec/models/topic_spec.rb | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index ec251d53..29185753 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -20,19 +20,19 @@ RSpec.describe Map, type: :model do end it 'prevents visibility if private' do - expect(map.authorize_to_show(other_user)).to eq true - expect(map.authorize_to_show(owner)).to eq true - expect(private_map.authorize_to_show(owner)).to eq true + expect(map.authorize_to_show(other_user)).to eq map + expect(map.authorize_to_show(owner)).to eq map + expect(private_map.authorize_to_show(owner)).to eq private_map expect(private_map.authorize_to_show(other_user)).to eq false end it 'only allows editing if commons or owned' do - expect(map.authorize_to_edit(other_user)).to eq true - expect(map.authorize_to_edit(owner)).to eq true + expect(map.authorize_to_edit(other_user)).to eq map + expect(map.authorize_to_edit(owner)).to eq map expect(private_map.authorize_to_edit(other_user)).to eq false - expect(private_map.authorize_to_edit(owner)).to eq true + expect(private_map.authorize_to_edit(owner)).to eq private_map expect(public_map.authorize_to_edit(other_user)).to eq false - expect(public_map.authorize_to_edit(owner)).to eq true + expect(public_map.authorize_to_edit(owner)).to eq public_map end end end diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index f42427b8..51a23647 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -24,19 +24,19 @@ RSpec.describe Synapse, type: :model do end it 'prevents visibility if private' do - expect(synapse.authorize_to_show(other_user)).to eq true - expect(synapse.authorize_to_show(owner)).to eq true - expect(private_synapse.authorize_to_show(owner)).to eq true + expect(synapse.authorize_to_show(other_user)).to eq synapse + expect(synapse.authorize_to_show(owner)).to eq synapse + expect(private_synapse.authorize_to_show(owner)).to eq private_synapse expect(private_synapse.authorize_to_show(other_user)).to eq false end it 'only allows editing if commons or owned' do - expect(synapse.authorize_to_edit(other_user)).to eq true - expect(synapse.authorize_to_edit(owner)).to eq true + expect(synapse.authorize_to_edit(other_user)).to eq synapse + expect(synapse.authorize_to_edit(owner)).to eq synapse expect(private_synapse.authorize_to_edit(other_user)).to eq false - expect(private_synapse.authorize_to_edit(owner)).to eq true + expect(private_synapse.authorize_to_edit(owner)).to eq private_synapse expect(public_synapse.authorize_to_edit(other_user)).to eq false - expect(public_synapse.authorize_to_edit(owner)).to eq true + expect(public_synapse.authorize_to_edit(owner)).to eq public_synapse end end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 4c4ce31d..45d47770 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -63,19 +63,19 @@ RSpec.describe Topic, type: :model do end it 'prevents visibility if private' do - expect(topic.authorize_to_show(other_user)).to eq true - expect(topic.authorize_to_show(owner)).to eq true - expect(private_topic.authorize_to_show(owner)).to eq true + expect(topic.authorize_to_show(other_user)).to eq topic + expect(topic.authorize_to_show(owner)).to eq topic + expect(private_topic.authorize_to_show(owner)).to eq private_topic expect(private_topic.authorize_to_show(other_user)).to eq false end it 'only allows editing if commons or owned' do - expect(topic.authorize_to_edit(other_user)).to eq true - expect(topic.authorize_to_edit(owner)).to eq true + expect(topic.authorize_to_edit(other_user)).to eq topic + expect(topic.authorize_to_edit(owner)).to eq topic expect(private_topic.authorize_to_edit(other_user)).to eq false - expect(private_topic.authorize_to_edit(owner)).to eq true + expect(private_topic.authorize_to_edit(owner)).to eq private_topic expect(public_topic.authorize_to_edit(other_user)).to eq false - expect(public_topic.authorize_to_edit(owner)).to eq true + expect(public_topic.authorize_to_edit(owner)).to eq public_topic end end end From 63e493959213426773e2191fef51d35a179c48e9 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:35:40 +0800 Subject: [PATCH 35/44] remove TODO --- spec/models/map_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 29185753..d1486192 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -1,7 +1,6 @@ require 'rails_helper' RSpec.describe Map, type: :model do - # TODO: what is it important to be sure about when working with a Map? it { is_expected.to belong_to :user } it { is_expected.to validate_presence_of :name } it { is_expected.to validate_presence_of :permission } From c7f7fa1d1bd64323cb14a7d1b86525af4fc27fdd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 18 Dec 2015 09:35:56 +0800 Subject: [PATCH 36/44] reorganize synapse spec pendingness --- spec/models/synapse_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index 51a23647..17fc8cdd 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' RSpec.describe Synapse, type: :model do - pending "add some examples to (or delete) #{__FILE__}" - pending "validate that desc can't be nil - important for javascript" it { is_expected.to belong_to :user } it { is_expected.to belong_to :topic1 } it { is_expected.to belong_to :topic2 } @@ -11,6 +9,8 @@ RSpec.describe Synapse, type: :model do it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } + pending "validate that desc can't be nil - important for javascript" + context 'permissions' do let(:owner) { create :user } let(:other_user) { create :user } From f85bf74b2eb7105087e13623bc2da4dace6f7dca Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 20 Dec 2015 21:55:10 +0800 Subject: [PATCH 37/44] synapse desc validation --- spec/models/synapse_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index 17fc8cdd..a1069805 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -8,8 +8,7 @@ RSpec.describe Synapse, type: :model do it { is_expected.to have_many :mappings } it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } - - pending "validate that desc can't be nil - important for javascript" + it { is_expected.to validate_length_of(:desc).is_at_least(0) } # TODO don't allow nil context 'permissions' do let(:owner) { create :user } From fe8794e8141e5f93bc48ab180cefbffa299d0ff7 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 20 Dec 2015 22:18:40 +0800 Subject: [PATCH 38/44] fix topic spec --- spec/models/topic_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 45d47770..b499daac 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -21,8 +21,8 @@ RSpec.describe Topic, type: :model do end context 'topic with one unpermitted synapse' do - let (:topic) { create(:topic) } - let (:synapse) { create(:synapse, permission: :private, topic1: topic, user: other_user) } + let (:synapse) { create(:synapse, permission: :private, user: other_user) } + let (:topic) { create(:topic, synapses1: [synapse]) } it 'returns false' do expect(topic.has_viewable_synapses(user)).to eq false @@ -30,8 +30,8 @@ RSpec.describe Topic, type: :model do end context 'topic with one permitted synapse' do - let (:topic) { create(:topic) } - let (:synapse) { create(:synapse, permission: :private, topic1: topic, user: user) } + let (:synapse) { create(:synapse, permission: :private, user: user) } + let(:topic) { create(:topic, synapses1: [synapse]) } it 'returns true' do expect(topic.has_viewable_synapses(user)).to eq true @@ -39,9 +39,9 @@ RSpec.describe Topic, type: :model do end context 'topic with one unpermitted, one permitted synapse' do - let (:topic) { create(:topic) } - let (:synapse1) { create(:synapse, permission: :private, topic1: topic, user: other_user) } - let (:synapse2) { create(:synapse, permission: :private, topic1: topic, user: user) } + let (:synapse1) { create(:synapse, permission: :private, user: other_user) } + let (:synapse2) { create(:synapse, permission: :private, user: user) } + let (:topic) { create(:topic, synapses1: [synapse1, synapse2]) } it 'returns true' do expect(topic.synapses.count).to eq 2 From 7930f1a21652b67396a99f474e0521d23d073028 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 20 Dec 2015 22:20:51 +0800 Subject: [PATCH 39/44] one test in metacode spec --- spec/models/metacode_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb index de0e79a1..10571a81 100644 --- a/spec/models/metacode_spec.rb +++ b/spec/models/metacode_spec.rb @@ -2,4 +2,5 @@ require 'rails_helper' RSpec.describe Metacode, type: :model do pending "add some examples to (or delete) #{__FILE__}" + it { is_expected.to have_many(:topics) } end From 7ea91273c8c3b20eb286d7c7678435e07bf89b26 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 21 Dec 2015 10:59:09 +0800 Subject: [PATCH 40/44] remove random string spec helper function in favour of factory girl sequences --- spec/factories/maps.rb | 2 +- spec/factories/synapses.rb | 2 +- spec/factories/topics.rb | 2 +- spec/factories/users.rb | 13 ++++++++----- spec/spec_helper.rb | 10 ---------- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/spec/factories/maps.rb b/spec/factories/maps.rb index bfda5a9a..a786d109 100644 --- a/spec/factories/maps.rb +++ b/spec/factories/maps.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :map do - name { random_string(10) } + sequence(:name) { |n| "Cool Map ##{n}" } permission :commons arranged { false } user diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb index 10fd74da..b83a0073 100644 --- a/spec/factories/synapses.rb +++ b/spec/factories/synapses.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :synapse do - desc { random_string(10) } + sequence(:desc) { |n| "Cool synapse ##{n}" } category :to permission :commons association :topic1, factory: :topic diff --git a/spec/factories/topics.rb b/spec/factories/topics.rb index c54301c1..17c69a25 100644 --- a/spec/factories/topics.rb +++ b/spec/factories/topics.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :topic do - name { random_string(10) } + sequence(:name) { |n| "Cool Topic ##{n}" } permission :commons user metacode diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 8bdcb17e..fb380e7c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,12 +1,15 @@ FactoryGirl.define do factory :user do - name { random_string(10) } - email { random_string(10) + '@' + random_string(10) + '.com' } - code { random_string(8) } - joinedwithcode { code } + sequence(:name) { |n| "Cool User ##{n}" } + sequence(:email) { |n| "cooluser#{n}@cooldomain.com" } + joinedwithcode { "qwertyui" } password 'omgwtfbbq' + transient do + validate false + end + # bypass validation of the joinedwithcode - to_create { |instance| instance.save(validate: false) } + to_create { |instance| instance.save(validate: instance.validate) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 14cfd1c7..a2b164b2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,14 +6,4 @@ RSpec.configure do |config| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true 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 -end - -def random_string(length = 10) - o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten - (0...length).map { o[rand(o.length)] }.join end From 61d914caba263dff0c024ec71e728ef6dcb03142 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 7 Jan 2016 15:32:11 +0800 Subject: [PATCH 41/44] 80 columns on RspecTesting.md --- doc/RspecTesting.md | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/doc/RspecTesting.md b/doc/RspecTesting.md index 5da5ec88..6c118407 100644 --- a/doc/RspecTesting.md +++ b/doc/RspecTesting.md @@ -1,25 +1,47 @@ ## Testing with RSpec -RSpec is a ruby gem that allows you to test your code base. This is great - every time you make a change, you can do some basic sanity checks to make sure you didn't break anything. +RSpec is a ruby gem that allows you to test your code base. This is great - +every time you make a change, you can do some basic sanity checks to make sure +you didn't break anything. -To test Metamaps, run `rspec` in the top level directory. It will automatically search the `spec` directory for files called `*_spec.rb`, and run them as tests. When it's done testing, it will print a report telling you how many tests failed. With luck, the number will be 0. +To test Metamaps, run `rspec` in the top level directory. It will automatically +search the `spec` directory for files called `*_spec.rb`, and run them as tests. +When it's done testing, it will print a report telling you how many tests +failed. With luck, the number will be 0. -At the time of writing, there are four directories in the spec folder. One, `support`, is for helper functions. `rails_helper.rb` and `spec_helper.rb` are also for helper functions. +Note that if your test database doesn't exist yet, you'll need to create it +first: -`factories` is for a gem called [factory-girl][factory-girl]. This gem lets you use the `create` and `build` functions to quickly create the simplest possible valid version of a given model. For instance: + RAILS_ENV=test rake db:create + +At the time of writing, there are four directories in the spec folder. One, +`support`, is for helper functions. `rails_helper.rb` and `spec_helper.rb` are +also for helper functions. + +`factories` is for a gem called [factory-girl][factory-girl]. This gem lets you +use the `create` and `build` functions to quickly create the simplest possible +valid version of a given model. For instance: let(:map1) { create :map } let(:ronald) { create :user, name: "Ronald" } let(:map2) { create :map, user: ronald } -As you can see, you can also customize the factories. You can read the full documentation at the link above or check the existing specs to see how it works. It is worth reading through the factories to see how they are defined. If you add a model, please create a factory for it that defines the minimum valid state for that model. +As you can see, you can also customize the factories. You can read the full +documentation at the link above or check the existing specs to see how it works. +It is worth reading through the factories to see how they are defined. If you +add a model to `app/models`, please also create a factory for it that defines +the minimum valid state for that model. -Finally, `models` and `controllers` have the actual spec files. Writing specs is usually fairly simple but you do need to understand the syntax. You can read more at [rspec.info][rspec-docs]. +Finally, `models` and `controllers` have the actual spec files. Writing specs is +usually fairly simple but you do need to understand the syntax. You can read +more at [rspec.info][rspec-docs]. -If you modify the metamaps codebase, please consider adding tests. This will help in a few ways: +If you modify the metamaps codebase, please consider adding tests verifying that +the added code works. This will help in a few ways: - Unrelated changes in the future that break your code will be spotted earlier - - Your changes will be more easily understood, since the *purpose* will be described by the spec + - Your changes will be more easily understood, since the *purpose* will be + described by the spec Happy testing! From 4469b29ec23038ae7a8971fb2dbf8cec263fa184 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 7 Jan 2016 15:32:19 +0800 Subject: [PATCH 42/44] in user model --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7c2a2202..bd3bf477 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User < ActiveRecord::Base validates_uniqueness_of :name # done by devise validates_uniqueness_of :email # done by devise - validates :joinedwithcode, :presence => true, :inclusion => { :in => User.all.pluck(:code), :message => "%{value} is not valid" }, :on => :create + validates :joinedwithcode, :presence => true, :inclusion => { :in => $codes, :message => "%{value} is not valid" }, :on => :create # This method associates the attribute ":image" with a file attachment has_attached_file :image, :styles => { From 4a1e4ef3337c084f2347316b6dbea4d24f985a3d Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 7 Jan 2016 15:47:45 +0800 Subject: [PATCH 43/44] refactor user factories to handle codes better --- spec/factories/users.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index fb380e7c..91da1d1c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,15 +1,29 @@ +# +# This file supports three factories, because code and joinedwithcode +# make things complicated! +# +# Generally, use :simple_user to generate users. It's simplest. +# +# If you want to test code generation, or need a setup with users that +# have actual codes, you'll need to specify one simple_user and then you +# can specify other :code_user users based on the pre-existing user's code. + FactoryGirl.define do - factory :user do + factory :code_user, class: User do sequence(:name) { |n| "Cool User ##{n}" } sequence(:email) { |n| "cooluser#{n}@cooldomain.com" } - joinedwithcode { "qwertyui" } password 'omgwtfbbq' - transient do - validate false - end + factory :simple_user, aliases: [:user] do + joinedwithcode { "qwertyui" } + code { "qwertyui" } - # bypass validation of the joinedwithcode - to_create { |instance| instance.save(validate: instance.validate) } + transient do + validate false + end + + # bypass validation of the joinedwithcode + to_create { |instance| instance.save(validate: instance.validate) } + end end end From 4be263c223f19e47ac3b8b1c4291cc7919919f1d Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 7 Jan 2016 16:06:35 +0800 Subject: [PATCH 44/44] prominence to rspec command --- doc/RspecTesting.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/RspecTesting.md b/doc/RspecTesting.md index 6c118407..82cf74f7 100644 --- a/doc/RspecTesting.md +++ b/doc/RspecTesting.md @@ -4,10 +4,14 @@ RSpec is a ruby gem that allows you to test your code base. This is great - every time you make a change, you can do some basic sanity checks to make sure you didn't break anything. -To test Metamaps, run `rspec` in the top level directory. It will automatically -search the `spec` directory for files called `*_spec.rb`, and run them as tests. -When it's done testing, it will print a report telling you how many tests -failed. With luck, the number will be 0. +To test Metamaps, run + + rspec + +in the top level directory. It will automatically search the `spec` directory +for files called `*_spec.rb`, and run them as tests. When it's done testing, it +will print a report telling you how many tests failed. With luck, the number +will be 0. Note that if your test database doesn't exist yet, you'll need to create it first: