diff --git a/Gemfile b/Gemfile index 819d9ad..e2c2bdb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,5 @@ source "https://rubygems.org" -ruby '2.0.0' - gem 'mechanize' gem 'sanitize' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index ab6d61d..dab114c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,7 +65,6 @@ GEM nokogiri (1.6.0) mini_portile (~> 0.5.0) ntlm-http (0.1.1) - pg (0.15.1) polyglot (0.3.3) rack (1.5.2) rack-protection (1.5.0) @@ -86,19 +85,19 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.1.0) - rspec (2.14.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.2) - rspec-expectations (2.14.0) + rspec (2.13.0) + rspec-core (~> 2.13.0) + rspec-expectations (~> 2.13.0) + rspec-mocks (~> 2.13.0) + rspec-core (2.13.1) + rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) - rspec-given (2.4.4) + rspec-given (2.4.3) rspec (>= 2.12) sorcerer (>= 0.3.7) - rspec-mocks (2.14.1) - sanitize (2.0.5) - nokogiri (>= 1.4.4) + rspec-mocks (2.13.1) + sanitize (2.0.4) + nokogiri (~> 1.6.0) sinatra (1.4.3) rack (~> 1.4) rack-protection (~> 1.4) @@ -136,7 +135,6 @@ DEPENDENCIES capybara factory_girl mechanize - pg rack rack-test rails diff --git a/dbconnect.rb b/dbconnect.rb index f1ae2c4..729da78 100644 --- a/dbconnect.rb +++ b/dbconnect.rb @@ -6,4 +6,4 @@ ActiveRecord::Base.establish_connection(:adapter=>'postgresql', :database=>'HEROKU_POSTGRESQL_AQUA') #personal preference -ActiveRecord::Base.pluralize_table_names = true +ActiveRecord::Base.pluralize_table_names = false \ No newline at end of file diff --git a/dbconnect.rb.orig b/dbconnect.rb.orig deleted file mode 100644 index 0fafb11..0000000 --- a/dbconnect.rb.orig +++ /dev/null @@ -1,13 +0,0 @@ -# default boilerplate -require 'rubygems' -require 'active_record' - -#change for your actual setup -ActiveRecord::Base.establish_connection(:adapter=>'postgresql', :database=>'HEROKU_POSTGRESQL_AQUA') - -#personal preference -<<<<<<< HEAD -ActiveRecord::Base.pluralize_table_names = true -======= -ActiveRecord::Base.pluralize_table_names = false ->>>>>>> 5d97379cdfad6b663d22b4f3f26550bc7394a9c3 diff --git a/migrations/db/004_create_authentication_table.rb b/migrations/db/004_create_authentication_table.rb new file mode 100644 index 0000000..6c873b2 --- /dev/null +++ b/migrations/db/004_create_authentication_table.rb @@ -0,0 +1,14 @@ +#the class name must be the camelcased version of the filename +class CreateAuthenticationTable < ActiveRecord::Migration + def up + create_table :authentication do |t| + t.string :server_name + t.string :server_address + t.string :authentication_token + end + end + + def down + drop_table :authentication + end +end \ No newline at end of file diff --git a/model/authentication.rb b/model/authentication.rb new file mode 100644 index 0000000..9489367 --- /dev/null +++ b/model/authentication.rb @@ -0,0 +1,9 @@ +require 'active_record' +require_relative "../dbconnect.rb" +#Include all database tables classes + +class Authentication < ActiveRecord::Base + + attr_accessible :server_name, :server_address, :authentication_token + +end \ No newline at end of file diff --git a/spec/start_spec.rb b/spec/start_spec.rb index e52239a..95b3600 100644 --- a/spec/start_spec.rb +++ b/spec/start_spec.rb @@ -43,4 +43,19 @@ page.has_selector?('input[name=\'q\']').should be_true end + describe "result of post request" do + let (:server) {Server.new('test.db')} + before {visit '/'} + + it "should respond with 200: positive test" do + fill_in 'q', :with=>"testing" + page.click_button 'search' + page.status_code.should == 200 + end + + it "should respond with 403 or 404: negative test" do + click_button 'search' + page.status_code.should == 404 or page.status_code.should == 403 + end + end end diff --git a/start.rb b/start.rb index 4a620f0..be608e0 100644 --- a/start.rb +++ b/start.rb @@ -1,5 +1,10 @@ require 'mechanize' require_relative './crawler/crawler.rb' +require_relative './dbconnect.rb' +require 'sinatra' + +set :server, 'webrick' + require_relative './model/word.rb' require 'sinatra' @@ -9,7 +14,20 @@ erb :form end +post '/form' do + @words = params[:words] + @link = params[:link_name] + auth = Authentication.where(:authentication_token=>params[:auth_token]) + + if auth.nil? + status 403 + else + status 200 + end + + erb :display +end def app Sinatra::Application diff --git a/views/display.erb b/views/display.erb new file mode 100644 index 0000000..6c4d4ad --- /dev/null +++ b/views/display.erb @@ -0,0 +1,2 @@ +

Words are <%= @words.join %>

+

Link is <%= @link %>

\ No newline at end of file