Merge pull request #65 from ENSL/develop

Develop
This commit is contained in:
simplefl 2015-10-28 18:12:31 +01:00
commit f07670850d
6 changed files with 112 additions and 876 deletions

View file

@ -1,2 +1,2 @@
ruby:
config/styles/ruby.yml
config_file: config/styles/ruby.yml

View file

@ -4,7 +4,19 @@ class Api::V1::UsersController < Api::V1::BaseController
end
def show
@user = User.find(params[:id])
if params[:format].nil? || params[:format] == "id"
@user = User.find(params[:id])
elsif params[:format] == "steamid"
steamid_i = params[:id].to_i
@user = User.first(conditions: { steamid: format("0:%d:%d", steamid_i % 2, steamid_i >> 1) })
elsif params[:format] == "steamidstr"
@user = User.first(conditions: { steamid: params[:id] })
end
if @user.nil?
raise ActionController::RoutingError.new("User Not Found")
end
if @user.steamid.present?
@steam = steam_profile @user
end
@ -16,6 +28,8 @@ class Api::V1::UsersController < Api::V1::BaseController
time_zone: @user.time_zone,
avatar: @user.profile.avatar.url,
admin: @user.admin?,
referee: @user.ref?,
caster: @user.caster?,
moderator: @user.gather_moderator?,
steam: @user.steamid.nil? ? nil : {
id: @user.steamid,
@ -30,7 +44,7 @@ class Api::V1::UsersController < Api::V1::BaseController
team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil
}
rescue ActiveRecord::RecordNotFound
raise ActionController::RoutingError.new('User Not Found')
raise ActionController::RoutingError.new("User Not Found")
end
private

40
app/views/users/_general.html.erb Normal file → Executable file
View file

@ -4,20 +4,32 @@
<dl>
<dt>Age</dt>
<dd><%= @user.age %></dd>
<dt>Country</dt>
<dd><%= @user.country %></dd>
<dt>Town</dt>
<dd><%= @user.profile.town %></dd>
<dt>SteamID</dt>
<dd>
<p><%= @user.steamid %></p>
<div id="steam-search" data-user-id="<%= @user.id %>">
<%= link_to "Search for Steam Account" %>
</div>
</dd>
<dt>Stream</dt>
<dd><%= @user.profile.stream.blank? ? "No Stream Provided" : @user.profile.stream %></dd>
</dd>
<% if !@user.country.blank? %>
<dt>Country</dt>
<dd><%= @user.country %></dd>
<% end %>
<% if !@user.profile.town.blank? %>
<dt>Town</dt>
<dd><%= @user.profile.town %></dd>
<% end %>
<% if !@user.steamid.blank? %>
<dt>SteamID</dt>
<dd>
<p><%= @user.steamid %></p>
<div id="steam-search" data-user-id="<%= @user.id %>">
<%= link_to "Search for Steam Account" %>
</div>
</dd>
<% end %>
<% if !@user.profile.stream.blank? %>
<dt>Stream</dt>
<dd><%= @user.profile.stream %></dd>
</dd>
<% end %>
</dl>
<h4>Contact</h4>

File diff suppressed because it is too large Load diff

View file

@ -10,16 +10,15 @@ describe Api::V1::UsersController do
@user = create :user, :chris
end
it "returns user data" do
get :show, id: @user.id
expect(response).to be_success
expect(json["id"]).to eq(@user.id)
expect(json["username"]).to eq(@user.username)
expect(json["country"]).to eq(@user.country)
expect(json["time_zone"]).to eq(@user.time_zone)
expect(json["admin"]).to eq(@user.admin?)
expect(json["moderator"]).to eq(@user.gather_moderator?)
def user_expectation(json, user)
expect(json["id"]).to eq(user.id)
expect(json["username"]).to eq(user.username)
expect(json["country"]).to eq(user.country)
expect(json["time_zone"]).to eq(user.time_zone)
expect(json["admin"]).to eq(user.admin?)
expect(json["referee"]).to eq(user.ref?)
expect(json["caster"]).to eq(user.caster?)
expect(json["moderator"]).to eq(user.gather_moderator?)
expect(json).to have_key("steam")
expect(json["steam"]).to have_key("id")
expect(json["steam"]).to have_key("url")
@ -30,6 +29,37 @@ describe Api::V1::UsersController do
expect(json["team"]).to be_nil
end
it "returns user data" do
get :show, id: @user.id
expect(response).to be_success
user_expectation(json, @user)
end
it "returns user data for query with id specified as format" do
get :show, id: @user.id, format: "id"
expect(response).to be_success
user_expectation(json, @user)
end
it "returns user data for a numeric steamid query" do
m = @user.steamid.match(/\A0:([01]):(\d{1,10})\Z/)
steamid = (m[2].to_i << 1) + m[1].to_i
get :show, id: steamid, format: "steamid"
expect(response).to be_success
user_expectation(json, @user)
end
it "returns user data for a string steamid query" do
get :show, id: @user.steamid, format: "steamidstr"
expect(response).to be_success
user_expectation(json, @user)
end
it "returns nulled steam data for users who had invalid steam ids" do
@user.steamid = nil
@user.save!

3
spec/features/users/stream_spec.rb Normal file → Executable file
View file

@ -7,7 +7,7 @@ feature "User Stream Information" do
feature "stream administration" do
scenario "user updates their stream" do
visit user_path(user)
expect(page).to have_content("No Stream Provided")
expect(page.html).to_not include("<dt>Stream</dt>")
fill_login_form(user, password)
click_button submit(:user, :login)
visit edit_user_path(user)
@ -17,6 +17,7 @@ feature "User Stream Information" do
click_button "Update Profile"
expect(page).to have_content(I18n.t(:users_update))
visit user_path(user)
expect(page.html).to include("<dt>Stream</dt>")
expect(page).to have_content(stream_url)
end
end