Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
source "https://rubygems.org"

ruby '2.0.0'

gem 'mechanize'
gem 'sanitize'
gem 'sinatra'
Expand Down
22 changes: 10 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -136,7 +135,6 @@ DEPENDENCIES
capybara
factory_girl
mechanize
pg
rack
rack-test
rails
Expand Down
2 changes: 1 addition & 1 deletion dbconnect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 0 additions & 13 deletions dbconnect.rb.orig

This file was deleted.

14 changes: 14 additions & 0 deletions migrations/db/004_create_authentication_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#the class name must be the camelcased version of the filename
class CreateAuthenticationTable < ActiveRecord::Migration
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the model for this ???

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
9 changes: 9 additions & 0 deletions model/authentication.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/start_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions start.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions views/display.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>Words are <%= @words.join %></p>
<p>Link is <%= @link %></p>