diff --git a/app/assets/javascripts/components/seat.js.jsx b/app/assets/javascripts/components/seat.js.jsx new file mode 100644 index 00000000..679ada86 --- /dev/null +++ b/app/assets/javascripts/components/seat.js.jsx @@ -0,0 +1,29 @@ +var Seat = React.createClass({ + + onClick: function(e) { + // TODO: Sit at table + $.ajax({ + url: window.location.pathname + '/sit', + type: 'POST', + dataType: 'json', + complete: function (jqXHR, textStatus) { + // callback + }, + success: function (data, textStatus, jqXHR) { + // success callback + }, + error: function (jqXHR, textStatus, errorThrown) { + // error callback + } + }); + }, + + render: function() { + return ( + + ); + } + +}); diff --git a/app/assets/javascripts/components/table.js.jsx b/app/assets/javascripts/components/table.js.jsx new file mode 100644 index 00000000..b847ea6d --- /dev/null +++ b/app/assets/javascripts/components/table.js.jsx @@ -0,0 +1,39 @@ +var Table = React.createClass({ + // TODO: Declare all propTypes + propTypes: { + title: React.PropTypes.string, + id: React.PropTypes.number, + url: React.PropTypes.string + }, + + getInitialState: function() { + return { + data: null, + id: "", + title: "" + }; + }, + + componentDidMount: function() { + $.getJSON(this.props.url, function(result) { + if (this.isMounted()) { + this.setState({ data: result }); + } + }.bind(this)); + }, + + render: function() { + if (!this.state.data) { + return
Loading...
; + } + return ( +
+

{this.state.data.title}

+ + + + +
+ ); + } +}); diff --git a/app/controllers/tables_controller.rb b/app/controllers/tables_controller.rb index a039d881..deb22a34 100644 --- a/app/controllers/tables_controller.rb +++ b/app/controllers/tables_controller.rb @@ -1,6 +1,8 @@ class TablesController < ApplicationController before_action :set_table, only: [:show, :edit, :update, :destroy] + respond_to :html, :json + # GET /tables # GET /tables.json def index diff --git a/app/views/tables/show.json.jbuilder b/app/views/tables/show.json.jbuilder new file mode 100644 index 00000000..ca42e255 --- /dev/null +++ b/app/views/tables/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @table, :id, :title, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 5bd9be85..f19e42a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,9 @@ Rails.application.routes.draw do resources :players - resources :tables + resources :tables do + resources :seats + resources :games + end resources :games do member do diff --git a/spec/features/visitors/table_index_spec.rb b/spec/features/tables/table_index_spec.rb similarity index 100% rename from spec/features/visitors/table_index_spec.rb rename to spec/features/tables/table_index_spec.rb diff --git a/spec/features/tables/table_join_spec.rb b/spec/features/tables/table_join_spec.rb new file mode 100644 index 00000000..a282031e --- /dev/null +++ b/spec/features/tables/table_join_spec.rb @@ -0,0 +1,41 @@ +# Feature: Table show +# As a visitor +# I want to view a table +# So I can sit and play a game +feature 'Table show', :devise do + context "As a visitor" do + before(:each) do + @table = FactoryGirl.create :table + visit tables_path + click_link @table.title + end + # Scenario: Visitor can view a table + # Given I am not signed in + # When I visit a table + # Then I see the table attributes + scenario 'visitor can see the table', js: true do + expect(page).to have_selector "#table-#{@table.id} > h1", @table.title + end + + scenario 'visitor can sit at the table', js: true do + click_button 'Sit' + expect(page).to have_content "Guest" + end + end + + context "As a user" do + # Scenario: User can view a table + # Given I am signed in + # When I click a table + # Then I see an index of tables + scenario 'visitor can see the table', js: true do + @table = FactoryGirl.create :table + # TODO: sign in + visit tables_path + click_link @table.title + expect(page).to have_button "Sit" + expect(page).to have_selector "#table-#{@table.id} > .title", @table.title + expect(current_path).to eq table_path(@table) + end + end +end