merging jam-admin into admin

This commit is contained in:
Seth Call 2013-09-16 03:15:31 +00:00
commit c8150c8aee
105 changed files with 3324 additions and 0 deletions

21
admin/.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/log/*.age
/tmp
*~
*.swp
artifacts
*.iml
.idea

1
admin/.rspec Normal file
View File

@ -0,0 +1 @@
--color

1
admin/.rvmrc Normal file
View File

@ -0,0 +1 @@
rvm use ruby-1.9.3-p327@jam-admin --create

96
admin/Gemfile Normal file
View File

@ -0,0 +1,96 @@
source 'https://rubygems.org'
source 'https://jamjam:blueberryjam@int.jamkazam.com/gems/'
# Look for $WORKSPACE, otherwise use "workspace" as dev path.
workspace = ENV["WORKSPACE"] || "~/workspace"
devenv = ENV["BUILD_NUMBER"].nil? # Jenkins sets a build number environment variable
if devenv
gem 'jam_db', :path=> "#{workspace}/jam-db/target/ruby_package"
gem 'jampb', :path => "#{workspace}/jam-pb/target/ruby/jampb"
gem 'jam_ruby', :path => "#{workspace}/jam-ruby"
else
gem 'jam_db'
gem 'jampb'
gem 'jam_ruby'
end
gem 'rails'
gem 'bootstrap-sass', '2.0.4'
gem 'bcrypt-ruby', '3.0.1'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
# this version is pinned due to this: https://github.com/gregbell/active_admin/issues/1939
gem 'coffee-script-source', '~> 1.4.0' # ADD THIS LINE, 1.5.0 doesn't compile ActiveAdmin JavaScript files
end
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'carrierwave'
gem 'uuidtools', '2.1.2'
gem 'bcrypt-ruby', '3.0.1'
gem 'jquery-rails', '2.3.0' # pinned because jquery-ui-rails was split from jquery-rails, but activeadmin doesn't support this gem yet
gem 'rails3-jquery-autocomplete'
gem 'activeadmin'
gem "meta_search", '>= 1.1.0.pre'
gem 'fog', "~> 1.3.1"
gem 'country-select'
gem 'aasm', '3.0.16'
gem 'postgres-copy'
gem 'aws-sdk'
gem 'eventmachine', '1.0.0'
gem 'amqp', '0.9.8'
gem 'logging-rails', :require => 'logging/rails'
gem 'pg_migrate' # ,'0.1.5' #:path => "#{workspace}/pg_migrate_ruby"
gem 'ruby-protocol-buffers', '1.2.2'
gem 'sendgrid', '1.1.0'
group :libv8 do
gem 'libv8', "~> 3.11.8"
end
group :development do
gem 'thin' # bundle exec rails server thin
end
# To use Jbuilder templates for JSON
# gem 'jbuilder'
group :production do
gem 'unicorn'
end
group :package do
gem 'fpm'
end
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
group :development, :test do
gem 'capybara'
gem 'rspec-rails'
gem 'guard-rspec', '0.5.5'
gem 'jasmine', '1.3.1'
gem 'pry'
gem 'execjs', '1.4.0'
gem 'therubyracer' #, '0.11.0beta8'
gem 'factory_girl_rails', '4.1.0'
gem 'database_cleaner', '0.7.0'
gem 'launchy'
end

10
admin/README.md Normal file
View File

@ -0,0 +1,10 @@
Jam-Admin
---------
jam-admin is a rails-based administrator portal.
Immediately the focus is on using active_scaffolding that provides visibility into our data model, and rudimentary CRUD control.
Overtime we can add more administrative functions and views, but initially this is one of the easiest ways to give 'powertools' behind the scenes with an entirely separate authentication model.

261
admin/README.rdoc Normal file
View File

@ -0,0 +1,261 @@
== Welcome to Rails
Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.
This pattern splits the view (also called the presentation) into "dumb"
templates that are primarily responsible for inserting pre-built data in between
HTML tags. The model contains the "smart" domain objects (such as Account,
Product, Person, Post) that holds all the business logic and knows how to
persist themselves to a database. The controller handles the incoming requests
(such as Save New Account, Update Product, Show Post) by manipulating the model
and directing data to the view.
In Rails, the model is handled by what's called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
database rows as objects and embellish these data objects with business logic
methods. You can read more about Active Record in
link:files/vendor/rails/activerecord/README.html.
The controller and view are handled by the Action Pack, which handles both
layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.
== Getting Started
1. At the command prompt, create a new Rails application:
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
2. Change directory to <tt>myapp</tt> and start the web server:
<tt>cd myapp; rails server</tt> (run with --help for options)
3. Go to http://localhost:3000/ and you'll see:
"Welcome aboard: You're riding Ruby on Rails!"
4. Follow the guidelines to start developing your application. You can find
the following resources handy:
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
== Debugging Rails
Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.
First area to check is the application log files. Have "tail -f" commands
running on the server.log and development.log. Rails will automatically display
debugging and runtime information to these files. Debugging info will also be
shown in the browser on requests from 127.0.0.1.
You can also log your own messages directly into the log file from your code
using the Ruby logger class from inside your controllers. Example:
class WeblogController < ActionController::Base
def destroy
@weblog = Weblog.find(params[:id])
@weblog.destroy
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
end
end
The result will be a message in your log file along the lines of:
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
More information on how to use the logger is at http://www.ruby-doc.org/core/
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
several books available online as well:
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
These two books will bring you up to speed on the Ruby language and also on
programming in general.
== Debugger
Debugger support is available through the debugger command when you start your
Mongrel or WEBrick server with --debugger. This means that you can break out of
execution at any point in the code, investigate and change the model, and then,
resume execution! You need to install ruby-debug to run the server in debugging
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
class WeblogController < ActionController::Base
def index
@posts = Post.all
debugger
end
end
So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect
=> "[#<Post:0x14a6be8
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
#<Post:0x14a6620
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"
...and even better, you can examine how your runtime objects actually work:
>> f = @posts.first
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)
Finally, when you're ready to resume execution, you can enter "cont".
== Console
The console is a Ruby shell, which allows you to interact with your
application's domain model. Here you'll have all parts of the application
configured, just like it is when the application is running. You can inspect
domain models, change values, and save to the database. Starting the script
without arguments will launch it in the development environment.
To start the console, run <tt>rails console</tt> from the application
directory.
Options:
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
made to the database.
* Passing an environment name as an argument will load the corresponding
environment. Example: <tt>rails console production</tt>.
To reload your controllers and models after launching the console run
<tt>reload!</tt>
More information about irb can be found at:
link:http://www.rubycentral.org/pickaxe/irb.html
== dbconsole
You can go to the command line of your database directly through <tt>rails
dbconsole</tt>. You would be connected to the database with the credentials
defined in database.yml. Starting the script without arguments will connect you
to the development database. Passing an argument will connect you to a different
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
PostgreSQL and SQLite 3.
== Description of Contents
The default directory structure of a generated Ruby on Rails application:
|-- app
| |-- assets
| |-- images
| |-- javascripts
| `-- stylesheets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
| `-- layouts
|-- config
| |-- environments
| |-- initializers
| `-- locales
|-- db
|-- doc
|-- lib
| `-- tasks
|-- log
|-- public
|-- script
|-- test
| |-- fixtures
| |-- functional
| |-- integration
| |-- performance
| `-- unit
|-- tmp
| |-- cache
| |-- pids
| |-- sessions
| `-- sockets
`-- vendor
|-- assets
`-- stylesheets
`-- plugins
app
Holds all the code that's specific to this particular application.
app/assets
Contains subdirectories for images, stylesheets, and JavaScript files.
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from
ApplicationController which itself descends from ActionController::Base.
app/models
Holds models that should be named like post.rb. Models descend from
ActiveRecord::Base by default.
app/views
Holds the template files for the view that should be named like
weblogs/index.html.erb for the WeblogsController#index action. All views use
eRuby syntax by default.
app/views/layouts
Holds the template files for layouts to be used with views. This models the
common header/footer method of wrapping views. In your views, define a layout
using the <tt>layout :default</tt> and create a file named default.html.erb.
Inside default.html.erb, call <% yield %> to render the view using this
layout.
app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are
generated for you automatically when using generators for controllers.
Helpers can be used to wrap functionality for your views into methods.
config
Configuration files for the Rails environment, the routing map, the database,
and other dependencies.
db
Contains the database schema in schema.rb. db/migrate contains all the
sequence of Migrations for your schema.
doc
This directory is where your application documentation will be stored when
generated using <tt>rake doc:app</tt>
lib
Application specific libraries. Basically, any kind of custom code that
doesn't belong under controllers, models, or helpers. This directory is in
the load path.
public
The directory available for the web server. Also contains the dispatchers and the
default HTML files. This should be set as the DOCUMENT_ROOT of your web
server.
script
Helper scripts for automation and generation.
test
Unit and functional tests along with fixtures. When using the rails generate
command, template test files will be generated for you and placed in this
directory.
vendor
External libraries that the application depends on. Also includes the plugins
subdirectory. If the app has frozen rails, those gems also go here, under
vendor/rails/. This directory is in the load path.

7
admin/Rakefile Normal file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
JamAdmin::Application.load_tasks

3
admin/app/admin/bands.rb Normal file
View File

@ -0,0 +1,3 @@
ActiveAdmin.register JamRuby::Band, :as => 'Band' do
end

View File

@ -0,0 +1,27 @@
ActiveAdmin.register JamRuby::CrashDump, :as => 'Crash Dump' do
# Note: a lame thing is it's not obvious how to make it search on email instead of user_id.
filter :timestamp
filter :user_email, :as => :string
filter :client_id
index do
column "Timestamp" do |post|
post.timestamp.strftime('%b %d %Y, %H:%M')
end
column "Client Type", :client_type
column "Dump URL" do |post|
link_to post.uri, post.uri
end
column "User ID", :user_id
# FIXME (?): This isn't performant (though it likely doesn't matter). Could probably do a join.
column "User Email" do |post|
unless post.user_id.nil?
post.user_email
end
end
column "Client ID", :client_id
actions
end
end

View File

@ -0,0 +1,51 @@
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
content :title => proc{ I18n.t("active_admin.dashboard") } do
div :class => "blank_slate_container", :id => "dashboard_default_message" do
span :class => "blank_slate" do
span "JamKazam Data Administration Portal"
small ul do
li "Admin users are users with the admin boolean set to true"
li "Create/Edit JamKazam users using the 'Jam User' menu in header"
li "Admin users are created/deleted when toggling the 'admin' flag for JamKazam users"
end
end
end
# Here is an example of a simple dashboard with columns and panels.
#
columns do
column do
panel "Recent Sessions" do
ul do
MusicSessionHistory.order('created_at desc').limit(5).map do |music_session|
li do
text_node "'#{music_session.description}' created by #{User.find(music_session.user_id).name} at #{music_session.created_at}, "
text_node " members: "
music_session.unique_users.each do |session_member|
text_node " #{session_member.name}"
end
end
# ul do
#
# end
#end
# li link_to(music_session.description, admin_post_path(music_session))
end
end
end
end
end
# column do
# panel "Info" do
# para "Welcome to ActiveAdmin."
# end
# end
# end
end # content
end

View File

@ -0,0 +1,24 @@
ActiveAdmin.register JamRuby::ArtifactUpdate do
menu :label => 'Artifacts'
config.sort_order = 'product,environment'
form :html => { :multipart => true } do |f|
f.inputs "Details" do
f.input :version, :hint => "Should match Jenkins build number of artifact"
f.input :environment, :hint => "Typically just 'public'"
f.input :product, :as => :select, :collection => JamRuby::ArtifactUpdate::PRODUCTS
end
f.inputs "Artifact Upload" do
f.input :uri, :as => :file, :hint => "Upload the artifact from Jenkins"
end
f.buttons
end
#collection_action :upload_artifact, :method => :post do
# # Do some CSV importing work here...
# redirect_to :action => :index, :notice => "CSV imported successfully!"
#end
end

View File

@ -0,0 +1,25 @@
ActiveAdmin.register JamRuby::InvitedUser do
menu :label => 'Invite Users'
config.sort_order = 'created_at'
form :html => { :multipart => true } do |f|
f.inputs "Required Data" do
f.input :email, :as => :email, :hint => "The email of the person you want to invite"
f.input :sender,:as => :select, :as => :select, :collection => User.where('admin = true'), :value => nil, :hint => "If you are sending a personalized invitation, then select a user"
f.input :autofriend, :hint => "Do you want the sender of this invite to be friends upon invitation acceptance?"
end
f.inputs "Optional Stuff" do
f.input :note, :input_html => { :class => 'autogrow' }, :hint => "You can add a personalized note, if you wish"
end
f.buttons
end
#collection_action :upload_artifact, :method => :post do
# # Do some CSV importing work here...
# redirect_to :action => :index, :notice => "CSV imported successfully!"
#end
end

View File

@ -0,0 +1,112 @@
ActiveAdmin.register JamRuby::User do
menu :label => 'Jam User'
config.sort_order = 'created_at DESC'
filter :email
filter :first_name
filter :last_name
filter :internet_service_provider
filter :created_at
filter :updated_at
form do |ff|
ff.inputs "Details" do
ff.input :email
ff.input :admin
ff.input :raw_password, :label => 'Password'
ff.input :first_name
ff.input :last_name
ff.input :city
ff.input :state
ff.input :country
ff.input :musician
ff.input :can_invite
ff.input :photo_url
ff.input :internet_service_provider
ff.input :session_settings
end
ff.inputs "Signup" do
ff.input :email_template, :label => 'Welcome Email Template Name'
ff.input :confirm_url, :label => 'Signup Confirm URL'
end
ff.actions
end
show do |user|
attributes_table do
row :id
row :email
row :admin
row :updated_at
row :created_at
row :musician
row :city
row :state
row :country
row :first_name
row :last_name
row :birth_date
row :gender
row :internet_service_provider
row :email_confirmed
row :image do user.photo_url ? image_tag(user.photo_url) : '' end
row :session_settings
row :can_invite
end
active_admin_comments
end
index do
column "ID" do |user|
link_to(truncate(user.id, {:length => 12}),
resource_path(user),
{:title => user.id})
end
column "Email" do |user|
link_to user.email, resource_path(user)
end
column :admin
column :updated_at
column :created_at
column :musician
column :city
column :state
column :country
column :first_name
column :last_name
column :birth_date
column :gender
column :internet_service_provider
column :email_confirmed
column :photo_url
column :session_settings
column :can_invite
# default_actions # use this for all view/edit/delete links
column "Actions" do |user|
links = ''.html_safe
links << link_to("View", resource_path(user), :class => "member_link view_link")
links << link_to("Edit", edit_resource_path(user), :class => "member_link edit_link")
links
end
end
controller do
def create
@jam_ruby_user = JamRuby::User.new(params[:jam_ruby_user])
@jam_ruby_user.administratively_created = true
if @jam_ruby_user.password.nil? || @jam_ruby_user.password.length == 0
# a nil password in the form means we simply won't create one; however,
# the password_digest has to be set to something to make 'has_secure_password' happy
@jam_ruby_user.password_digest = SecureRandom.urlsafe_base64
end
# call `create!` to ensure that the rest of the action continues as normal
create!
end
end
end

View File

@ -0,0 +1,46 @@
ActiveAdmin.register JamRuby::MusicSessionHistory, :as => 'Music Session History' do
config.filters = false
config.per_page = 50
config.clear_action_items!
controller do
def scoped_collection
@music_session_histories ||= end_of_association_chain
.includes([:user, :band])
.order('created_at DESC')
end
end
index :as => :block do |msh|
div :for => msh do
h3 "Session ##{msh.music_session_id}: #{msh.created_at.strftime('%b %d %Y, %H:%M')}"
columns do
column do
panel 'Session Details' do
attributes_table_for(msh) do
row :description
row :duration do |msh| "#{msh.duration_minutes} minutes" end
row :active do |msh| msh.session_removed_at.nil? end
row :creator do |msh| auto_link(msh.user, msh.user.try(:email)) end
row :band do |msh| auto_link(msh.band, msh.band.try(:name)) end
row :genres
row :perf_data do |msg| link_to('Data Link', "http://#{msh.perf_uri}") end
end
end
end
column do
panel 'User Details' do
table_for(msuh = msh.music_session_user_histories) do
column :user do |msuh| msuh.user_email end
column :joined do |msuh| msuh.created_at.strftime('%b %d %Y, %H:%M') end
column :duration do |msuh| "#{msuh.duration_minutes} minutes" end
column :active do |msuh| msuh.session_removed_at.nil? end
end
end
end
end
end
end
end

8
admin/app/admin/user.rb Normal file
View File

@ -0,0 +1,8 @@
ActiveAdmin.register JamRuby::User do
# define routes for "autocomplete :admin_user, :email"
collection_action :autocomplete_user_email, :method => :get
controller do
autocomplete :invited_user, :email
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -0,0 +1,2 @@
//= require active_admin/base
//= require autocomplete-rails

View File

@ -0,0 +1,15 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

View File

@ -0,0 +1,29 @@
// SASS variable overrides must be declared before loading up Active Admin's styles.
//
// To view the variables that Active Admin provides, take a look at
// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
// Active Admin source.
//
// For example, to change the sidebar width:
// $sidebar-width: 242px;
// Active Admin's got SASS!
@import "active_admin/mixins";
@import "active_admin/base";
// Overriding any non-variable SASS must be done after the fact.
// For example, to change the default status-tag color:
//
// body.active_admin {
// .status_tag { background: #6090DB; }
// }
//
// Notice that Active Admin CSS rules are nested within a
// 'body.active_admin' selector to prevent conflicts with
// other pages in the app. It is best to wrap your changes in a
// namespace so they are properly recognized. You have options
// if you e.g. want different styles for different namespaces:
//
// .active_admin applies to any Active Admin namespace
// .admin_namespace applies to the admin namespace (eg: /admin)
// .other_namespace applies to a custom namespace named other (eg: /other)

View File

@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/

View File

@ -0,0 +1,4 @@
.version-info {
font-size:small;
color:lightgray;
}

View File

@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end

View File

@ -0,0 +1,29 @@
class ArtifactsController < ApplicationController
respond_to :json
# create or update a client_artifact row
def update_artifacts
product = params[:product]
version = params[:version]
uri = params[:uri]
file = params[:file]
environment = params[:environment]
@artifact = ArtifactUpdate.find_or_create_by_product_and_environment(product, environment)
@artifact.version = version
@artifact.uri = file
@artifact.save
unless @artifact.errors.any?
render :json => {}, :status => :ok
else
response.status = :unprocessable_entity
respond_with @artifact
end
end
end

View File

@ -0,0 +1,3 @@
module ApplicationHelper
end

View File

@ -0,0 +1,2 @@
module JamSessionMembersHelper
end

View File

@ -0,0 +1,2 @@
module JamSessionsHelper
end

View File

@ -0,0 +1,7 @@
module MetaHelper
def version()
"web=#{::JamAdmin::VERSION} lib=#{JamRuby::VERSION} db=#{JamDb::VERSION}"
end
end

View File

@ -0,0 +1,2 @@
module UsersHelper
end

View File

View File

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>JamAdmin</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
<div class="version-info"><%= version %></div>
</body>
</html>

75
admin/build Executable file
View File

@ -0,0 +1,75 @@
#!/bin/bash
echo "updating dependencies"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# 'target' is the output directory
rm -rf $DIR/target
mkdir $DIR/target
mkdir $DIR/target/deb
# put all dependencies into vendor/bundle
rm -rf vendor/bundle
rm Gemfile.lock # if we don't want versions to float, pin it in the Gemfile, not count on Gemfile.lock
bundle install --path vendor/bundle
bundle update
if [ "$?" = "0" ]; then
echo "success: updated dependencies"
else
echo "could not update dependencies"
exit 1
fi
if [ -z $SKIP_TESTS ]; then
echo "running rspec tests"
bundle exec rspec
if [ "$?" = "0" ]; then
echo "success: ran rspec tests"
else
echo "running rspec tests failed."
exit 1
fi
fi
if [ -n "$PACKAGE" ]; then
if [ -z "$BUILD_NUMBER" ]; then
echo "BUILD NUMBER is not defined"
exit 1
fi
cat > lib/jam_admin/version.rb << EOF
module JamAdmin
VERSION = "0.1.$BUILD_NUMBER"
end
EOF
type -P dpkg-architecture > /dev/null
if [ "$?" = "0" ]; then
ARCH=`dpkg-architecture -qDEB_HOST_ARCH`
else
echo "WARN: unable to determine architecture."
ARCH=`all`
fi
set -e
# cache all gems local, and tell bundle to use local gems only
bundle install --path vendor/bundle --local
# prepare production acssets
rm -rf $DIR/public/assets
bundle exec rake assets:precompile RAILS_ENV=production
# create debian using fpm
bundle exec fpm -s dir -t deb -p target/deb/jam-admin_0.1.${BUILD_NUMBER}_${ARCH}.deb -n "jam-admin" -v "0.1.$BUILD_NUMBER" --prefix /var/lib/jam-admin --after-install $DIR/script/package/post-install.sh --before-install $DIR/script/package/pre-install.sh --before-remove $DIR/script/package/pre-uninstall.sh --after-remove $DIR/script/package/post-uninstall.sh Gemfile .bundle config Rakefile script config.ru lib public vendor app
fi
echo "build complete"

4
admin/config.ru Normal file
View File

@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run JamAdmin::Application

View File

@ -0,0 +1,86 @@
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# initialize ActiveRecord's db connection
# why? Because user.rb uses validates :acceptance, which needs a connection to the database. if there is better way...
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))[Rails.env])
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
include JamRuby
module JamAdmin
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- 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}/lib)
# 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.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config.active_record.observers = "JamRuby::InvitedUserObserver"
config.assets.prefix = ENV['RAILS_RELATIVE_URL_ROOT'] || '/'
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# to make active_admin assets precompile
config.assets.precompile += ['active_admin.css', 'active_admin.js', 'active_admin/print.css']
# set to false to instead use amazon. You will also need to supply amazon secrets
config.store_artifacts_to_disk = true
# these only need to be set if store_artifact_to_files = false
config.aws_artifact_access_key_id = ENV['AWS_KEY']
config.aws_artifact_secret_access_key = ENV['AWS_SECRET']
config.aws_artifact_region = 'us-east-1'
config.aws_artifact_bucket_public = 'jamkazam-dev-public'
config.aws_artifact_bucket = 'jamkazam-dev'
config.aws_artifact_cache = '315576000'
end
end

18
admin/config/boot.rb Normal file
View File

@ -0,0 +1,18 @@
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
# change default port of jam-admin so that it's easy to run both
require 'rails/commands/server'
module Rails
class Server
alias :default_options_alias :default_options
def default_options
default_options_alias.merge!(:Port => 3333)
end
end
end

29
admin/config/database.yml Normal file
View File

@ -0,0 +1,29 @@
test:
adapter: postgresql
database: jam_admin_test
host: localhost
port: 5432
pool: 3
username: postgres
password: postgres
timeout: 2000
encoding: unicode
development:
adapter: postgresql
database: jam
host: localhost
pool: 5
username: postgres
password: postgres
timeout: 2000
encoding: unicode
production:
adapter: postgresql
database: jam
username: postgres
password: postgres
host: localhost
pool: 5
timeout: 5000

View File

@ -0,0 +1,5 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
JamAdmin::Application.initialize!

View File

@ -0,0 +1,46 @@
JamAdmin::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# FIXME: set this to something reasonable (activeadmin docs dictate this be set)
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
# Set the logging destination(s)
config.log_to = %w[stdout file]
# Show the logging configuration on STDOUT
config.show_log_configuration = true
end

View File

@ -0,0 +1,76 @@
JamAdmin::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
# Set the logging destination(s)
config.log_to = %w[file]
# Show the logging configuration on STDOUT
config.show_log_configuration = false
config.aws_artifact_bucket_public = 'jamkazam-public'
config.aws_artifact_bucket = 'jamkazam'
end

View File

@ -0,0 +1,37 @@
JamAdmin::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end

View File

@ -0,0 +1,162 @@
class Footer < ActiveAdmin::Component
def build
super(id: "footer")
para "version info: web=#{::JamAdmin::VERSION} lib=#{JamRuby::VERSION} db=#{JamDb::VERSION}"
end
end
ActiveAdmin.setup do |config|
# == Site Title
#
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = "Jam Admin"
# Set the link url for the title. For example, to take
# users to your main site. Defaults to no link.
#
# config.site_title_link = "/"
# Set an optional image to be displayed for the header
# instead of a string (overrides :site_title)
#
# Note: Recommended image height is 21px to properly fit in the header
#
# config.site_title_image = "/images/logo.png"
# == Default Namespace
#
# Set the default namespace each administration resource
# will be added to.
#
# eg:
# config.default_namespace = :hello_world
#
# This will create resources in the HelloWorld module and
# will namespace routes to /hello_world/*
#
# To set no namespace by default, use:
# config.default_namespace = false
#
# Default:
# config.default_namespace = :admin
#
# You can customize the settings for each namespace by using
# a namespace block. For example, to change the site title
# within a namespace:
#
# config.namespace :admin do |admin|
# admin.site_title = "Custom Admin Title"
# end
#
# This will ONLY change the title for the admin section. Other
# namespaces will continue to use the main "site_title" configuration.
# == User Authentication
#
# Active Admin will automatically call an authentication
# method in a before filter of all controller actions to
# ensure that there is a currently logged in admin user.
#
# This setting changes the method which Active Admin calls
# within the controller.
#config.authentication_method = :authenticate_admin_user!
# == Current User
#
# Active Admin will associate actions with the current
# user performing them.
#
# This setting changes the method which Active Admin calls
# to return the currently logged in user.
#config.current_user_method = :current_admin_user
# == Logging Out
#
# Active Admin displays a logout link on each screen. These
# settings configure the location and method used for the link.
#
# This setting changes the path where the link points to. If it's
# a string, the strings is used as the path. If it's a Symbol, we
# will call the method to return the path.
#
# Default:
config.logout_link_path = :destroy_user_session_path
# This setting changes the http method used when rendering the
# link. For example :get, :delete, :put, etc..
#
# Default:
# config.logout_link_method = :get
# == Root
#
# Set the action to call for the root path. You can set different
# roots for each namespace.
#
# Default:
# config.root_to = 'dashboard#index'
# == Admin Comments
#
# Admin comments allow you to add comments to any model for admin use.
# Admin comments are enabled by default.
#
# Default:
# config.allow_comments = true
#
# You can turn them on and off for any given namespace by using a
# namespace config block.
#
# Eg:
# config.namespace :without_comments do |without_comments|
# without_comments.allow_comments = false
# end
# == Batch Actions
#
# Enable and disable Batch Actions
#
config.batch_actions = true
# == Controller Filters
#
# You can add before, after and around filters to all of your
# Active Admin resources and pages from here.
#
# config.before_filter :do_something_awesome
# == Register Stylesheets & Javascripts
#
# We recommend using the built in Active Admin layout and loading
# up your own stylesheets / javascripts to customize the look
# and feel.
#
# To load a stylesheet:
# config.register_stylesheet 'my_stylesheet.css'
# You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
# config.register_stylesheet 'my_print_stylesheet.css', :media => :print
#
# To load a javascript file:
# config.register_javascript 'my_javascript.js'
# == CSV options
#
# Set the CSV builder separator (default is ",")
# config.csv_column_separator = ','
#
# Set the CSV builder options (default is {})
# config.csv_options = {}
config.view_factory.footer = Footer
end

View File

@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View File

@ -0,0 +1,25 @@
require 'carrierwave'
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
CarrierWave.configure do |config|
if JamAdmin::Application.config.store_artifacts_to_disk
config.storage = :file
else
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => JamAdmin::Application.config.aws_artifact_access_key_id,
:aws_secret_access_key => JamAdmin::Application.config.aws_artifact_secret_access_key,
:region => JamAdmin::Application.config.aws_artifact_region,
}
config.fog_directory = JamAdmin::Application.config.aws_artifact_bucket_public # required
config.fog_public = true # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>"max-age=#{JamAdmin::Application.config.aws_artifact_cache}"} # optional, defaults to {}
end
end
require 'carrierwave/orm/activerecord'

View File

@ -0,0 +1,3 @@
module Constants
ADMIN_USER_EMAILS = [] # ['admin@jamkazam.com']
end

View File

@ -0,0 +1,234 @@
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
config.secret_key = '19569035c21af920ad2f124c3e7f26016f0aa5f5ce83e44a32e5a76adabf65d0d4e2c360bb44ff0b8660228843cfae8d74faa878aa328aefe849aaad3ff4bed3'
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record'
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [ :email ]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
# find_for_authentication method and considered in your model lookup. For instance,
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
# The same considerations mentioned for authentication_keys also apply to request_keys.
# config.request_keys = []
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# given strategies, for example, `config.params_authenticatable = [:database]` will
# enable it only for database (email + password) authentication.
# config.params_authenticatable = true
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
# It can be set to an array that will enable http authentication only for the
# given strategies, for example, `config.http_authenticatable = [:token]` will
# enable it only for token authentication.
# config.http_authenticatable = false
# If http headers should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# :http_auth and :token_auth by adding those symbols to the array below.
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing :skip => :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments.
config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password.
# config.pepper = "b2185ac545e304261231585a88ac1f9bcf833af8db2b5e775e0b52558e4a47aada589267507da325be6f1fa4391e306c59f3c1971914361ba3c82a19fb41a0a7"
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
# confirming his account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming his account,
# access will be blocked just in the third day. Default is 0.days, meaning
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# config.rememberable_options = {}
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
# config.password_length = 6..128
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# If true, expires auth token on session timeout.
# config.expire_auth_token_on_timeout = false
# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [ :email ]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
# config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
# config.maximum_attempts = 20
# Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours
# ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
# REST_AUTH_SITE_KEY to pepper)
# config.encryptor = :sha512
# ==> Configuration for :token_authenticatable
# Defines name of the authentication token params key
# config.token_authentication_key = :auth_token
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
# config.default_scope = :user
# Set this configuration to false if you want /users/sign_out to sign out
# only the current scope. By default, Devise signs out all scopes.
# config.sign_out_all_scopes = true
# ==> Navigation configuration
# Lists the formats that should be treated as navigational. Formats like
# :html, should redirect to the sign in page when the user does not have
# access, but formats like :xml or :json, should return 401.
#
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ["*/*", :html]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block.
#
# config.warden do |manager|
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end
# ==> Mountable engine configurations
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
# is mountable, there are some extra configurations to be taken into account.
# The following options are available, assuming the engine is mounted as:
#
# mount MyEngine, at: "/my_engine"
#
# The router that invoked `devise_for`, in the example above, would be:
# config.router_name = :my_engine
#
# When using omniauth, Devise cannot automatically set Omniauth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = "/my_engine/users/auth"
end

View File

@ -0,0 +1,11 @@
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = Rails.env == "test" ? :test : :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => "www.jamkazam.com",
:authentication => :plain,
:user_name => "jamkazam",
:password => "jamjamblueberryjam",
:enable_starttls_auto => true
}

View File

@ -0,0 +1,15 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@ -0,0 +1,82 @@
class JamRuby::User
EMAIL_TMPL_WELCOME = 'welcome_message'
EMAIL_TMPL_WELCOME_BETA = 'welcome_betauser'
EMAIL_TMPL_WELCOMES = [EMAIL_TMPL_WELCOME_BETA, EMAIL_TMPL_WELCOME]
CONFIRM_URL = "http://www.jamkazam.com/confirm" # we can't get request.host_with_port, so hard-code confirm url (with user override)
attr_accessible :admin, :raw_password, :musician, :can_invite, :photo_url, :internet_service_provider, :session_settings, :confirm_url, :email_template # :invite_email
def raw_password
''
end
def raw_password= pw
unless pw.blank?
# change_password(pw, pw)
self.updating_password = true
self.password = pw
self.password_confirmation = pw
if au = self.admin_user
au.update_attribute(:encrypted_password, self.password_digest)
end
end
end
def country
@country = "United States"
end
def musician
@musician = true
end
def confirm_url
@signup_confirm_url ||= CONFIRM_URL
end
def confirm_url= url
@signup_confirm_url = url
end
def email_template
@signup_email_template ||= EMAIL_TMPL_WELCOME_BETA
end
def email_template= tmpl
@signup_email_template = tmpl
end
def admin_user
User.where(:email => self.email)[0]
end
after_create do
self.update_attribute(:signup_token, SecureRandom.urlsafe_base64)
url = confirm_url
url.chomp!('/')
# only supporting two welcome templates ATM
if EMAIL_TMPL_WELCOMES.index(self.email_template).nil?
self.email_template = EMAIL_TMPL_WELCOME
end
# UserMailer.send(self.email_template, self, "#{url}/#{self.signup_token}").deliver
end
after_save do
logger.debug("*** after_save: #{self.admin_changed?}")
if self.admin_changed?
if self.admin
if self.admin_user.nil?
au = User.create(:email => self.email)
au.update_attribute(:encrypted_password, self.password_digest)
end
else
self.admin_user.try(:destroy)
end
end
end
end

View File

@ -0,0 +1,13 @@
if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
def per(value = nil) per_page(value) end
def total_count() count end
end
end
module CollectionMethods
alias_method :num_pages, :total_pages
end
end
end

View File

@ -0,0 +1,5 @@
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

View File

@ -0,0 +1,7 @@
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
JamAdmin::Application.config.secret_token = 'e27a8deff5bc124d1c74cb86ebf38ac4a246091b859bcccf4f8076454e0ff3e04ffc87c9a0f4ddc801c4753e20b2a3cf06e5efc815cfe8e6377f912b737c5f77'

View File

@ -0,0 +1,8 @@
# Be sure to restart your server when you modify this file.
JamAdmin::Application.config.session_store :cookie_store, key: '_jam-admin_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# JamAdmin::Application.config.session_store :active_record_store

View File

@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end

View File

@ -0,0 +1,58 @@
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
updated: 'You updated your account successfully.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authenticated from %{kind} account.'
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'

View File

@ -0,0 +1,5 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "Hello world"

111
admin/config/logging.rb Normal file
View File

@ -0,0 +1,111 @@
Logging::Rails.configure do |config|
# Objects will be converted to strings using the :format_as method.
Logging.format_as :inspect
# The default layout used by the appenders.
layout = Logging.layouts.pattern(:pattern => '[%d] %-5l %c : %m\n')
# Setup a color scheme called 'bright' than can be used to add color codes
# to the pattern layout. Color schemes should only be used with appenders
# that write to STDOUT or STDERR; inserting terminal color codes into a file
# is generally considered bad form.
#
Logging.color_scheme( 'bright',
:levels => {
:info => :green,
:warn => :yellow,
:error => :red,
:fatal => [:white, :on_red]
},
:date => :blue,
:logger => :cyan,
:message => :magenta
)
# Configure an appender that will write log events to STDOUT. A colorized
# pattern layout is used to format the log events into strings before
# writing.
#
Logging.appenders.stdout( 'stdout',
:auto_flushing => true,
:layout => Logging.layouts.pattern(
:pattern => '[%d] %-5l %c : %m\n',
:color_scheme => 'bright'
)
) if config.log_to.include? 'stdout'
# Configure an appender that will write log events to a file. The file will
# be rolled on a daily basis, and the past 7 rolled files will be kept.
# Older files will be deleted. The default pattern layout is used when
# formatting log events into strings.
#
Logging.appenders.rolling_file( 'file',
:filename => config.paths['log'].first,
:keep => 7,
:age => 'daily',
:truncate => false,
:auto_flushing => true,
:layout => layout
) if config.log_to.include? 'file'
# Configure an appender that will send an email for "error" and "fatal" log
# events. All other log events will be ignored. Furthermore, log events will
# be buffered for one minute (or 200 events) before an email is sent. This
# is done to prevent a flood of messages.
#
Logging.appenders.email( 'email',
:from => "server@#{config.action_mailer.smtp_settings[:domain]}",
:to => "developers@#{config.action_mailer.smtp_settings[:domain]}",
:subject => "Rails Error [#{%x(uname -n).strip}]",
:server => config.action_mailer.smtp_settings[:address],
:domain => config.action_mailer.smtp_settings[:domain],
:acct => config.action_mailer.smtp_settings[:user_name],
:passwd => config.action_mailer.smtp_settings[:password],
:authtype => config.action_mailer.smtp_settings[:authentication],
:auto_flushing => 200, # send an email after 200 messages have been buffered
:flush_period => 60, # send an email after one minute
:level => :error, # only process log events that are "error" or "fatal"
:layout => layout
) if config.log_to.include? 'email'
# Setup the root logger with the Rails log level and the desired set of
# appenders. The list of appenders to use should be set in the environment
# specific configuration file.
#
# For example, in a production application you would not want to log to
# STDOUT, but you would want to send an email for "error" and "fatal"
# messages:
#
# => config/environments/production.rb
#
# config.log_to = %w[file email]
#
# In development you would want to log to STDOUT and possibly to a file:
#
# => config/environments/development.rb
#
# config.log_to = %w[stdout file]
#
Logging.logger.root.level = config.log_level
Logging.logger.root.appenders = config.log_to unless config.log_to.empty?
# Under Phusion Passenger smart spawning, we need to reopen all IO streams
# after workers have forked.
#
# The rolling file appender uses shared file locks to ensure that only one
# process will roll the log file. Each process writing to the file must have
# its own open file descriptor for `flock` to function properly. Reopening
# the file descriptors after forking ensures that each worker has a unique
# file descriptor.
#
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
Logging.reopen if forked
end
end
end

73
admin/config/routes.rb Normal file
View File

@ -0,0 +1,73 @@
JamAdmin::Application.routes.draw do
# ActiveAdmin::Devise.config,
devise_for :users, :class_name => "JamRuby::User", :path_prefix => '/admin', :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}
scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
root :to => "admin/dashboard#index"
ActiveAdmin.routes(self)
match '/api/artifacts' => 'artifacts#update_artifacts', :via => :post
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
end

102
admin/config/unicorn.rb Normal file
View File

@ -0,0 +1,102 @@
# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 4
# Since Unicorn is never exposed to outside clients, it does not need to
# run on the standard HTTP port (80), there is no reason to start Unicorn
# as root unless it's from system init scripts.
# If running the master process as root and the workers as an unprivileged
# user, do this to switch euid/egid in the workers (also chowns logs):
user "jam-admin", "jam-admin"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/var/lib/jam-admin" # available in 0.94.0+
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/tmp/.sock", :backlog => 64
listen 3100, :tcp_nopush => true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
# feel free to point this anywhere accessible on the filesystem
pid "/var/run/jam-admin.pid"
# By default, the Unicorn logger will write to stderr.
# Additionally, ome applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path "/var/lib/jam-admin/log/unicorn.stderr.log"
stdout_path "/var/lib/jam-admin/log/unicorn.stdout.log"
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
# Enable this flag to have unicorn test client connections by writing the
# beginning of the HTTP headers before calling the application. This
# prevents calling the application for connections that have disconnected
# while queued. This is only guaranteed to detect clients on the same
# host unicorn runs on, and unlikely to detect disconnects even on a
# fast LAN.
check_client_connection false
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
# The following is only recommended for memory/DB-constrained
# installations. It is not needed if your system can house
# twice as many worker_processes as you have configured.
#
# # This allows a new master process to incrementally
# # phase out the old master process with SIGTTOU to avoid a
# # thundering herd (especially in the "preload_app false" case)
# # when doing a transparent upgrade. The last worker spawned
# # will then kill off the old master process with a SIGQUIT.
# old_pid = "#{server.config[:pid]}.oldbin"
# if old_pid != server.pid
# begin
# sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
# Process.kill(sig, File.read(old_pid).to_i)
# rescue Errno::ENOENT, Errno::ESRCH
# end
# end
#
# Throttle the master from forking too quickly by sleeping. Due
# to the implementation of standard Unix signal handlers, this
# helps (but does not completely) prevent identical, repeated signals
# from being lost when the receiving process is busy.
# sleep 1
end
after_fork do |server, worker|
# per-process listener ports for debugging/admin/migrations
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
end

433
admin/db/schema.rb Normal file
View File

@ -0,0 +1,433 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130104141813) do
create_table "active_admin_comments", :force => true do |t|
t.string "resource_id", :null => false
t.string "resource_type", :null => false
t.integer "author_id"
t.string "author_type"
t.text "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "namespace"
end
add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id"
create_table "admin_users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
create_table "band_invitations", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64
t.string "band_id", :limit => 64
t.boolean "accepted"
t.string "creator_id", :limit => 64
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "bands", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "name", :limit => 1024, :null => false
t.string "website", :limit => 4000
t.string "biography", :limit => 4000, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "city", :limit => 100
t.string "state", :limit => 2
t.string "country", :limit => 100
t.string "photo_url", :limit => 2048
t.string "logo_url", :limit => 2048
end
create_table "bands_followers", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "band_id", :limit => 64, :null => false
t.string "follower_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "bands_followers", ["band_id", "follower_id"], :name => "band_follower_uniqkey", :unique => true
create_table "bands_genres", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "band_id", :limit => 64, :null => false
t.string "genre_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "bands_genres", ["band_id", "genre_id"], :name => "band_genre_uniqkey", :unique => true
create_table "bands_likers", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "band_id", :limit => 64, :null => false
t.string "liker_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "bands_likers", ["band_id", "liker_id"], :name => "band_liker_uniqkey", :unique => true
create_table "bands_musicians", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "band_id", :limit => 64, :null => false
t.string "user_id", :limit => 64, :null => false
t.boolean "admin", :default => false, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "bands_musicians", ["band_id", "user_id"], :name => "band_musician_uniqkey", :unique => true
create_table "bands_recordings", :id => false, :force => true do |t|
t.string "band_id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
end
add_index "bands_recordings", ["band_id", "recording_id"], :name => "band_recording_uniqkey", :unique => true
create_table "connections", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64
t.string "client_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "music_session_id", :limit => 64
t.string "ip_address", :limit => 64
t.boolean "as_musician"
end
add_index "connections", ["client_id"], :name => "connections_client_id_key", :unique => true
create_table "fan_invitations", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "sender_id", :limit => 64
t.string "receiver_id", :limit => 64
t.string "music_session_id", :limit => 64
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "friend_requests", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64
t.string "friend_id", :limit => 64
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "status", :limit => 50
t.string "message", :limit => 4000
end
create_table "friendships", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64
t.string "friend_id", :limit => 64
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "friendships", ["user_id", "friend_id"], :name => "user_friend_uniqkey", :unique => true
create_table "genres", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "description", :limit => 1024, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "genres_music_sessions", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "genre_id", :limit => 64
t.string "music_session_id", :limit => 64
end
create_table "instruments", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "description", :limit => 1024, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "popularity", :default => 0, :null => false
end
create_table "invitations", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "sender_id", :limit => 64
t.string "receiver_id", :limit => 64
t.string "music_session_id", :limit => 64
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "join_request_id", :limit => 64
end
add_index "invitations", ["sender_id", "receiver_id", "music_session_id"], :name => "invitations_uniqkey", :unique => true
create_table "join_requests", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64
t.string "music_session_id", :limit => 64
t.string "text", :limit => 2000
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "join_requests", ["user_id", "music_session_id"], :name => "user_music_session_uniqkey", :unique => true
create_table "max_mind", :id => false, :force => true do |t|
t.integer "ip_bottom"
t.integer "ip_top"
t.string "country", :limit => 64
t.string "region", :limit => 64
t.string "city"
end
add_index "max_mind", ["ip_bottom"], :name => "max_mind_ip_bottom_idx"
add_index "max_mind", ["ip_top"], :name => "max_mind_ip_top_idx"
create_table "music_sessions", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "description", :limit => 8000
t.string "user_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "musician_access", :null => false
t.string "band_id", :limit => 64
t.boolean "approval_required", :null => false
t.boolean "fan_access", :null => false
t.boolean "fan_chat", :null => false
end
create_table "music_sessions_comments", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "music_session_id", :limit => 64, :null => false
t.string "creator_id", :limit => 64, :null => false
t.string "comment", :limit => 4000, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "music_sessions_history", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "music_session_id", :limit => 64, :null => false
t.string "description", :limit => 8000
t.string "user_id", :limit => 64, :null => false
t.string "band_id", :limit => 64
t.string "genres"
t.datetime "created_at", :null => false
t.datetime "session_removed_at"
end
add_index "music_sessions_history", ["music_session_id"], :name => "music_session_uniqkey", :unique => true
create_table "music_sessions_likers", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "music_session_id", :limit => 64, :null => false
t.string "liker_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "music_sessions_likers", ["music_session_id", "liker_id"], :name => "music_sessions_liker_uniqkey", :unique => true
create_table "music_sessions_user_history", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "music_session_id", :limit => 64, :null => false
t.string "user_id", :limit => 64, :null => false
t.string "client_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
end
create_table "musicians_instruments", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64, :null => false
t.string "instrument_id", :limit => 64, :null => false
t.integer "proficiency_level", :limit => 2, :null => false
t.integer "priority", :limit => 2, :default => 1, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "musicians_instruments", ["user_id", "instrument_id"], :name => "musician_instrument_uniqkey", :unique => true
create_table "musicians_recordings", :id => false, :force => true do |t|
t.string "user_id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
end
add_index "musicians_recordings", ["user_id", "recording_id"], :name => "musician_recording_uniqkey", :unique => true
create_table "recordings", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "description", :limit => 200, :null => false
t.boolean "public", :default => true, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "creator_id", :limit => 64, :null => false
t.string "updater_id", :limit => 64, :null => false
end
create_table "recordings_comments", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
t.string "creator_id", :limit => 64, :null => false
t.string "comment", :limit => 4000, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "recordings_downloads", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
t.string "downloader_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "recordings_genres", :id => false, :force => true do |t|
t.string "recording_id", :limit => 64, :null => false
t.string "genre_id", :limit => 64, :null => false
end
add_index "recordings_genres", ["recording_id", "genre_id"], :name => "recording_genre_uniqkey", :unique => true
create_table "recordings_likers", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
t.string "liker_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "recordings_likers", ["recording_id", "liker_id"], :name => "recording_liker_uniqkey", :unique => true
create_table "recordings_plays", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
t.string "player_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "sessions_plays", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "music_session_id", :limit => 64, :null => false
t.string "player_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "tracks", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "connection_id", :limit => 64
t.string "instrument_id", :limit => 64
t.string "sound", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_authorizations", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64
t.string "uid", :null => false
t.string "provider", :null => false
t.string "token"
t.datetime "token_expiration"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "user_authorizations", ["user_id"], :name => "user_authorizations_user_id_idx"
create_table "users", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "email", :null => false
t.string "remember_token"
t.string "password_digest", :null => false
t.boolean "admin", :default => false, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "musician", :default => false, :null => false
t.string "city", :limit => 100
t.string "state", :limit => 100
t.string "country", :limit => 100
t.string "first_name", :limit => 50, :null => false
t.string "last_name", :limit => 50, :null => false
t.date "birth_date"
t.string "gender", :limit => 1, :default => "M", :null => false
t.string "internet_service_provider", :limit => 50
t.string "signup_token"
t.boolean "email_confirmed", :default => false
t.string "photo_url", :limit => 2048
t.string "session_settings", :limit => 4000
t.string "reset_password_token", :limit => 64
t.datetime "reset_password_token_created"
t.boolean "can_invite", :default => true, :null => false
end
add_index "users", ["email"], :name => "users_email_key", :unique => true
add_index "users", ["remember_token"], :name => "remember_token_idx"
add_index "users", ["remember_token"], :name => "users_remember_token_key", :unique => true
add_index "users", ["signup_token"], :name => "users_signup_token_key", :unique => true
create_table "users_favorites", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64, :null => false
t.string "recording_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "users_favorites", ["user_id", "recording_id"], :name => "user_favorite_uniqkey", :unique => true
create_table "users_followers", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64, :null => false
t.string "follower_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "users_followers", ["user_id", "follower_id"], :name => "user_follower_uniqkey", :unique => true
create_table "users_likers", :id => false, :force => true do |t|
t.string "id", :limit => 64, :null => false
t.string "user_id", :limit => 64, :null => false
t.string "liker_id", :limit => 64, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "users_likers", ["user_id", "liker_id"], :name => "user_liker_uniqkey", :unique => true
end

22
admin/db/seeds.rb Normal file
View File

@ -0,0 +1,22 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
Constants::ADMIN_USER_EMAILS.each do |admin_email|
if AdminUser.find_by_email(admin_email).nil?
if 'production' == Rails.env
pw = Utils::random_password(16)
else
pw = 'jam123'
end
AdminUser.create!(:email => admin_email,
:password => pw,
:password_confirmation => pw)
end
end
AdminUser::sync_users

13
admin/doc/README_FOR_APP Normal file
View File

@ -0,0 +1,13 @@
Use this README file to introduce your application and point to useful places in the API for learning more.
Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
* bundle exec rake db:seed
* JamRuby::User#admin toggles creation/deletion of AdminUser accounts
* Admin accounts have no corresponding JamRuby::User accounts
* Constants::ADMIN_USER_EMAILS creates master admin account from db/seeds.rb

29
admin/jenkins Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
DEB_SERVER=http://localhost:9010/apt-`uname -p`
echo "starting build..."
./build
if [ "$?" = "0" ]; then
echo "build succeeded"
if [ ! -z "$PACKAGE" ]; then
echo "publishing ubuntu package (.deb)"
DEBPATH=`find target/deb -name *.deb`
DEBNAME=`basename $DEBPATH`
curl -f -T $DEBPATH $DEB_SERVER/$DEBNAME
if [ "$?" != "0" ]; then
echo "deb publish failed"
exit 1
fi
echo "done publishing deb"
fi
else
echo "build failed"
exit 1
fi

View File

View File

@ -0,0 +1,3 @@
module JamAdmin
VERSION = "0.0.1"
end

0
admin/lib/tasks/.gitkeep Normal file
View File

6
admin/lib/utils.rb Normal file
View File

@ -0,0 +1,6 @@
module Utils
def self::random_password(size = 16)
chars = ((('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0))
(1..size).collect{|a| cc = chars[rand(chars.size)]; 0==rand(2) ? cc.upcase : cc }.join
end
end

0
admin/log/.gitkeep Normal file
View File

26
admin/public/404.html Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
</body>
</html>

26
admin/public/422.html Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/422.html -->
<div class="dialog">
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
</body>
</html>

25
admin/public/500.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<h1>We're sorry, but something went wrong.</h1>
</div>
</body>
</html>

0
admin/public/favicon.ico Normal file
View File

5
admin/public/robots.txt Normal file
View File

@ -0,0 +1,5 @@
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-Agent: *
# Disallow: /

4
admin/run.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# meant to be run on www.jamkazam.com, pre-chef
sudo su jam-admin -c "RAILS_RELATIVE_URL_ROOT=/admin nohup bundle exec rails s &"

View File

@ -0,0 +1,7 @@
description "jam-admin"
start on startup
start on runlevel [2345]
stop on runlevel [016]
exec start-stop-daemon --start --chdir /var/lib/jam-admin --exec /var/lib/jam-admin/script/package/upstart-run.sh

View File

@ -0,0 +1,20 @@
#!/bin/sh
set -eu
NAME="jam-admin"
USER="$NAME"
GROUP="$NAME"
# copy upstart file
cp /var/lib/$NAME/script/package/$NAME.conf /etc/init/$NAME.conf
mkdir -p /var/lib/$NAME/log
mkdir -p /var/lib/$NAME/tmp
mkdir -p /etc/$NAME
mkdir -p /var/log/$NAME
chown -R $USER:$GROUP /var/lib/$NAME
chown -R $USER:$GROUP /etc/$NAME
chown -R $USER:$GROUP /var/log/$NAME

View File

@ -0,0 +1,27 @@
#!/bin/sh
NAME="jam-admin"
set -e
if [ "$1" = "remove" ]
then
set +e
# stop the process, if any is found. we don't want this failing to cause an error, though.
sudo stop $NAME
set -e
if [ -f /etc/init/$NAME.conf ]; then
rm /etc/init/$NAME.conf
fi
fi
if [ "$1" = "purge" ]
then
if [ -d /var/lib/$NAME ]; then
rm -rf /var/lib/$NAME
fi
userdel $NAME
fi

View File

@ -0,0 +1,36 @@
#!/bin/sh
set -eu
NAME="jam-admin"
HOME="/var/lib/$NAME"
USER="$NAME"
GROUP="$NAME"
# if NIS is used, then errors can occur but be non-fatal
if which ypwhich >/dev/null 2>&1 && ypwhich >/dev/null 2>&1
then
set +e
fi
if ! getent group "$GROUP" >/dev/null
then
addgroup --system "$GROUP" >/dev/null
fi
# creating user if it isn't already there
if ! getent passwd "$USER" >/dev/null
then
adduser \
--system \
--home $HOME \
--shell /bin/false \
--disabled-login \
--ingroup "$GROUP" \
--gecos "$USER" \
"$USER" >/dev/null
fi
# NISno longer a possible problem; stop ignoring errors
set -e

View File

View File

@ -0,0 +1,20 @@
#!/bin/bash -l
# default config values
PORT=3000
BUILD_NUMBER=1
CONFIG_FILE="/etc/jam-admin/upstart.conf"
if [ -e "$CONFIG_FILE" ]; then
. "$CONFIG_FILE"
fi
# I don't like doing this, but the next command (bundle exec) retouches/generates
# the gemfile. This unfortunately means the next debian update doesn't update this file.
# Ultimately this means an old Gemfile.lock is left behind for a new package,
# and bundle won't run because it thinks it has the wrong versions of gems
rm -f Gemfile.lock
BUILD_NUMBER=$BUILD_NUMBER exec bundle exec unicorn_rails -p $PORT -E production -c config/unicorn.rb # -D
#BUILD_NUMBER=$BUILD_NUMBER /usr/local/rbenv/shims/bundle exec rails s -p $PORT

6
admin/script/rails Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'

49
admin/spec/factories.rb Normal file
View File

@ -0,0 +1,49 @@
FactoryGirl.define do
factory :user, :class => JamRuby::User do
sequence(:email) { |n| "person_#{n}@example.com"}
sequence(:first_name) { |n| "Person" }
sequence(:last_name) { |n| "#{n}" }
password "foobar"
password_confirmation "foobar"
email_confirmed true
musician true
city "Apex"
state "NC"
country "USA"
terms_of_service true
factory :admin do
admin true
end
before(:create) do |user|
user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user)
end
factory :single_user_session do
after(:create) do |user, evaluator|
music_session = FactoryGirl.create(:music_session, :creator => user)
connection = FactoryGirl.create(:connection, :user => user, :music_session => music_session)
end
end
end
factory :artifact_update, :class => JamRuby::ArtifactUpdate do
sequence(:version) { |n| "0.1.#{n}" }
uri { "http://somewhere/jkclient.msi" }
product { "JamClient/Win32" }
environment { "public" }
sha1 { "blurp" }
end
factory :musician_instrument, :class=> JamRuby::MusicianInstrument do
instrument { Instrument.find('electric guitar') }
proficiency_level 1
priority 0
end
factory :instrument, :class => JamRuby::Instrument do
description { |n| "Instrument #{n}" }
end
end

View File

@ -0,0 +1,35 @@
require 'spec_helper'
describe "Artifact Update" do
include UsesTempFiles
ARTIFACT_FILE='jkclient-0.1.1.exe'
subject { page }
let(:user) { FactoryGirl.create(:admin) }
before { sign_in user }
describe "crud" do
before { visit admin_jam_ruby_artifact_updates_path }
it { should have_selector('h2', text: "Jam Ruby Artifact Updates") }
describe "upload artifact" do
in_directory_with_file(ARTIFACT_FILE)
before do
visit new_admin_jam_ruby_artifact_update_path
fill_in "jam_ruby_artifact_update_version", with: "1"
fill_in "jam_ruby_artifact_update_environment", with: "public"
select('JamClient/Win32', from: "jam_ruby_artifact_update_product")
fill_in "jam_ruby_artifact_update_environment", with: "public"
attach_file("jam_ruby_artifact_update_uri", ARTIFACT_FILE)
click_button "Create Artifact update"
end
it {
should have_selector('#main_content .panel:first-child h3', text: "Jam Ruby Artifact Update Details" ) }
end
end
end

View File

@ -0,0 +1,36 @@
require 'spec_helper'
describe InvitedUser do
subject { page }
# create an administrative user
let(:user) { FactoryGirl.create(:admin) }
before { sign_in user }
describe "enduser management" do
# let's go the management page for users
before { visit admin_jam_ruby_invited_users_path }
it { should have_selector('h2', text: "Jam Ruby Invited Users") }
describe "create service invite" do
before do
# create a new user
UserMailer.deliveries.clear
visit new_admin_jam_ruby_invited_user_path
fill_in "jam_ruby_invited_user_email", with: "some_silly_guy@jamkazam.com"
#fill_in "jam_ruby_invited_user_sender_id", with: "some_silly_guy@jamkazam.com"
#fill_in "jam_ruby_invited_user_autofriend", with: "some_silly_guy@jamkazam.com"
click_button "Create Invited user"
end
it { should have_selector('#main_content .panel:first-child h3', text: "Jam Ruby Invited User Details" ); }
it { UserMailer.deliveries.length.should == 1 }
end
end
end

28
admin/spec/spec_db.rb Normal file
View File

@ -0,0 +1,28 @@
class SpecDb
TEST_DB_NAME="jam_admin_test"
def self.recreate_database(db_config)
recreate_database_jdbc(db_config)
end
def self.recreate_database_jdbc(db_config)
db_test_name = db_config["database"]
# jump into the 'postgres' database, just so we have somewhere to 'land' other than our test db,
# since we are going to drop/recreate it
db_config["database"] = "postgres"
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{db_test_name}")
ActiveRecord::Base.connection.execute("CREATE DATABASE #{db_test_name}")
db_config["database"] = db_test_name
JamDb::Migrator.new.migrate(:dbname => db_config["database"], :user => db_config["username"], :password => db_config["password"], :host => db_config["host"])
end
def self.recreate_database_pg
conn = PG::Connection.open("dbname=postgres")
conn.exec("DROP DATABASE IF EXISTS #{TEST_DB_NAME}")
conn.exec("CREATE DATABASE #{TEST_DB_NAME}")
JamDb::Migrator.new.migrate(:dbname => TEST_DB_NAME)
end
end

62
admin/spec/spec_helper.rb Normal file
View File

@ -0,0 +1,62 @@
ENV["RAILS_ENV"] ||= 'test'
# provision database
require 'active_record'
require 'jam_db'
require 'spec_db'
# recreate test database and migrate it
db_config = YAML::load(File.open('config/database.yml'))["test"]
SpecDb::recreate_database(db_config)
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["test"])
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'jam_ruby'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# load capybara
require 'capybara/rails'
#include Rails.application.routes.url_helpers
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# 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
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# 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"
end

View File

@ -0,0 +1,33 @@
#http://gabebw.wordpress.com/2011/03/21/temp-files-in-rspec/
# this will make a folder jam-ruby/spec/tmp if used in an rspec test, and delete it after
# our .gitignore would also keep spec/tmp out, if somehow it did not get deleted.
module UsesTempFiles
def self.included(example_group)
example_group.extend(self)
end
def in_directory_with_file(file)
before do
@pwd = Dir.pwd
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
FileUtils.mkdir_p(@tmp_dir)
Dir.chdir(@tmp_dir)
FileUtils.mkdir_p(File.dirname(file))
FileUtils.touch(file)
end
define_method(:content_for_file) do |content|
f = File.new(File.join(@tmp_dir, file), 'a+')
f.write(content)
f.flush # VERY IMPORTANT
f.close
end
after do
Dir.chdir(@pwd)
FileUtils.rm_rf(@tmp_dir)
end
end
end

View File

@ -0,0 +1,15 @@
include ApplicationHelper
def cookie_jar
Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
end
def sign_in(user)
visit new_user_session_path # login page
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
# Sign in when not using Capybara as well.
#cookie_jar[:remember_token] = user.remember_token
end

0
admin/test/fixtures/.gitkeep vendored Normal file
View File

View File

@ -0,0 +1,11 @@
# 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

7
admin/test/fixtures/jam_sessions.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name: MyString
two:
name: MyString

15
admin/test/fixtures/users.yml vendored Normal file
View File

@ -0,0 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name: MyString
email: MyString
remember_token: MyString
password_digest: MyString
admin: false
two:
name: MyString
email: MyString
remember_token: MyString
password_digest: MyString
admin: false

View File

View File

@ -0,0 +1,49 @@
require 'test_helper'
class JamSessionMembersControllerTest < ActionController::TestCase
setup do
@jam_session_member = jam_session_members(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:jam_session_members)
end
test "should get new" do
get :new
assert_response :success
end
test "should create jam_session_member" do
assert_difference('JamSessionMember.count') do
post :create, jam_session_member: { }
end
assert_redirected_to jam_session_member_path(assigns(:jam_session_member))
end
test "should show jam_session_member" do
get :show, id: @jam_session_member
assert_response :success
end
test "should get edit" do
get :edit, id: @jam_session_member
assert_response :success
end
test "should update jam_session_member" do
put :update, id: @jam_session_member, jam_session_member: { }
assert_redirected_to jam_session_member_path(assigns(:jam_session_member))
end
test "should destroy jam_session_member" do
assert_difference('JamSessionMember.count', -1) do
delete :destroy, id: @jam_session_member
end
assert_redirected_to jam_session_members_path
end
end

View File

@ -0,0 +1,49 @@
require 'test_helper'
class JamSessionsControllerTest < ActionController::TestCase
setup do
@jam_session = jam_sessions(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:jam_sessions)
end
test "should get new" do
get :new
assert_response :success
end
test "should create jam_session" do
assert_difference('JamSession.count') do
post :create, jam_session: { name: @jam_session.name }
end
assert_redirected_to jam_session_path(assigns(:jam_session))
end
test "should show jam_session" do
get :show, id: @jam_session
assert_response :success
end
test "should get edit" do
get :edit, id: @jam_session
assert_response :success
end
test "should update jam_session" do
put :update, id: @jam_session, jam_session: { name: @jam_session.name }
assert_redirected_to jam_session_path(assigns(:jam_session))
end
test "should destroy jam_session" do
assert_difference('JamSession.count', -1) do
delete :destroy, id: @jam_session
end
assert_redirected_to jam_sessions_path
end
end

View File

@ -0,0 +1,49 @@
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
setup do
@user = users(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:users)
end
test "should get new" do
get :new
assert_response :success
end
test "should create user" do
assert_difference('User.count') do
post :create, user: { admin: @user.admin, email: @user.email, name: @user.name, password_digest: @user.password_digest, remember_token: @user.remember_token }
end
assert_redirected_to user_path(assigns(:user))
end
test "should show user" do
get :show, id: @user
assert_response :success
end
test "should get edit" do
get :edit, id: @user
assert_response :success
end
test "should update user" do
put :update, id: @user, user: { admin: @user.admin, email: @user.email, name: @user.name, password_digest: @user.password_digest, remember_token: @user.remember_token }
assert_redirected_to user_path(assigns(:user))
end
test "should destroy user" do
assert_difference('User.count', -1) do
delete :destroy, id: @user
end
assert_redirected_to users_path
end
end

View File

View File

@ -0,0 +1,12 @@
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

13
admin/test/test_helper.rb Normal file
View File

@ -0,0 +1,13 @@
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

0
admin/test/unit/.gitkeep Normal file
View File

View File

@ -0,0 +1,7 @@
require 'test_helper'
class JamSessionMemberTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

Some files were not shown because too many files have changed in this diff Show More