diff --git a/Gemfile b/Gemfile index a0b68ae59..660e2f614 100644 --- a/Gemfile +++ b/Gemfile @@ -17,11 +17,11 @@ gem 'coffee-rails', '~> 4.0.0' # Use jquery as the JavaScript library gem 'jquery-rails' -# Turbolinks makes following links in your web application faster. +# Turbolinks makes following links in your web application faster. # Read more: https://github.com/rails/turbolinks gem 'turbolinks' -# Build JSON APIs with ease. +# Build JSON APIs with ease. # Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' @@ -34,18 +34,21 @@ group :assets do end group :development do - # debugging - gem 'pry' - # faster dev load time gem 'unicorn' - # Spring speeds up development by keeping your application running in the background. + # Spring speeds up development by keeping your application running in the background. # Read more: https://github.com/rails/spring gem 'spring' -end -group :development do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0' end + +group :development, :test do + gem 'fabrication', '~> 2.11.3' + gem 'faker', '~> 1.3.0' + gem 'pry' + gem 'rspec-rails', '~> 3.0.1' + gem 'shoulda-matchers', '~> 2.6.1', require: false +end diff --git a/Gemfile.lock b/Gemfile.lock index 232327e95..2fd42a5c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM tzinfo (~> 1.1) arel (5.0.1.20140414130214) builder (3.2.2) + coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -36,8 +37,12 @@ GEM coffee-script-source execjs coffee-script-source (1.7.0) + diff-lcs (1.2.5) erubis (2.7.0) execjs (2.2.0) + fabrication (2.11.3) + faker (1.3.0) + i18n (~> 0.5) hike (1.2.3) i18n (0.6.9) jbuilder (2.1.0) @@ -47,14 +52,21 @@ GEM railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) + kgio (2.9.2) + libv8 (3.16.14.3) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) + method_source (0.8.2) mime-types (1.25.1) minitest (5.3.4) multi_json (1.10.1) pg (0.17.1) polyglot (0.3.5) + pry (0.10.0) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) @@ -73,9 +85,27 @@ GEM activesupport (= 4.1.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.13.0) rake (10.3.2) rdoc (4.1.1) json (~> 1.4) + ref (1.0.5) + rspec-core (3.0.1) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.1) + rspec-support (~> 3.0.0) + rspec-rails (3.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.0) sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -85,6 +115,9 @@ GEM sdoc (0.4.0) json (~> 1.8) rdoc (~> 4.0, < 5.0) + shoulda-matchers (2.6.1) + activesupport (>= 3.0.0) + slop (3.5.0) spring (1.1.3) sprockets (2.11.0) hike (~> 1.2) @@ -95,6 +128,9 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) + therubyracer (0.12.1) + libv8 (~> 3.16.14.0) + ref thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) @@ -108,18 +144,29 @@ GEM uglifier (2.5.0) execjs (>= 0.3.0) json (>= 1.8.0) + unicorn (4.8.3) + kgio (~> 2.6) + rack + raindrops (~> 0.7) PLATFORMS ruby DEPENDENCIES coffee-rails (~> 4.0.0) + fabrication (~> 2.11.3) + faker (~> 1.3.0) jbuilder (~> 2.0) jquery-rails pg + pry rails (= 4.1.1) + rspec-rails (~> 3.0.1) sass-rails (~> 4.0.3) sdoc (~> 0.4.0) + shoulda-matchers (~> 2.6.1) spring + therubyracer turbolinks uglifier (>= 1.3.0) + unicorn diff --git a/app/models/.keep b/app/models/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/models/address.rb b/app/models/address.rb new file mode 100644 index 000000000..55937ecb7 --- /dev/null +++ b/app/models/address.rb @@ -0,0 +1,4 @@ +class Address < ActiveRecord::Base + belongs_to :contact + belongs_to :country +end diff --git a/app/models/contact.rb b/app/models/contact.rb new file mode 100644 index 000000000..d22b6f87c --- /dev/null +++ b/app/models/contact.rb @@ -0,0 +1,3 @@ +class Contact < ActiveRecord::Base + has_many :addresses +end diff --git a/app/models/country.rb b/app/models/country.rb new file mode 100644 index 000000000..01435d729 --- /dev/null +++ b/app/models/country.rb @@ -0,0 +1,3 @@ +class Country < ActiveRecord::Base + +end diff --git a/app/models/domain.rb b/app/models/domain.rb new file mode 100644 index 000000000..17eca90f6 --- /dev/null +++ b/app/models/domain.rb @@ -0,0 +1,7 @@ +class Domain < ActiveRecord::Base + belongs_to :registrar + belongs_to :ns_set + belongs_to :owner_contact, class_name: 'Contact' + belongs_to :technical_contact, class_name: 'Contact' + belongs_to :admin_contact, class_name: 'Contact' +end diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb new file mode 100644 index 000000000..e8c0fe484 --- /dev/null +++ b/app/models/nameserver.rb @@ -0,0 +1,3 @@ +class Nameserver < ActiveRecord::Base + has_and_belongs_to_many :ns_sets +end diff --git a/app/models/ns_set.rb b/app/models/ns_set.rb new file mode 100644 index 000000000..72e429151 --- /dev/null +++ b/app/models/ns_set.rb @@ -0,0 +1,5 @@ +class NsSet < ActiveRecord::Base + belongs_to :registrar + has_many :domains + has_and_belongs_to_many :nameservers +end diff --git a/app/models/registrar.rb b/app/models/registrar.rb new file mode 100644 index 000000000..b77efa067 --- /dev/null +++ b/app/models/registrar.rb @@ -0,0 +1,5 @@ +class Registrar < ActiveRecord::Base + belongs_to :country + has_many :domains + has_many :ns_sets +end diff --git a/app/models/right.rb b/app/models/right.rb new file mode 100644 index 000000000..8ff413610 --- /dev/null +++ b/app/models/right.rb @@ -0,0 +1,3 @@ +class Right < ActiveRecord::Base + has_and_belongs_to_many :roles +end diff --git a/app/models/role.rb b/app/models/role.rb new file mode 100644 index 000000000..b0ca561c8 --- /dev/null +++ b/app/models/role.rb @@ -0,0 +1,4 @@ +class Role < ActiveRecord::Base + has_many :users + has_and_belongs_to_many :rights +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..cacbd61cb --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ActiveRecord::Base + belongs_to :role +end diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 000000000..0c86b5c6f --- /dev/null +++ b/bin/rspec @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'rspec') diff --git a/db/migrate/20140616073945_init.rb b/db/migrate/20140616073945_init.rb new file mode 100644 index 000000000..25211a15e --- /dev/null +++ b/db/migrate/20140616073945_init.rb @@ -0,0 +1,125 @@ +class Init < ActiveRecord::Migration + def change + create_table :domains do |t| + t.string :name #ascii, utf8 will be converted on the fly + t.integer :registrar_id #registripidaja + t.datetime :registered_at + t.string :status + t.datetime :valid_from + t.datetime :valid_to + t.integer :owner_contact_id + t.integer :admin_contact_id + t.integer :technical_contact_id + t.integer :ns_set_id + t.string :auth_info + #t.integer :keyset_id #dnssec + + t.timestamps + end + + # this will be a huge table? + create_table :contacts do |t| + t.string :code #CID:STRING:OID + t.string :name + t.string :type #organisation / juridical / citizen #rails specific variable + t.string :reg_no #identity code or registration number for organisation + + # can a person have one or more of these contacts? + t.string :phone + t.string :email + t.string :fax + + t.timestamps + end + + create_table :addresses do |t| #needs a better name? + t.integer :contact_id + t.integer :country_id + t.string :city + t.string :address #Street + house + apartment #needs a better name + t.string :zip + + t.timestamps + end + + create_table :country_id do |t| + t.string :iso + t.string :name + + t.timestamps + end + + create_table :registrars do |t| + t.string :name + t.string :reg_no + t.string :vat_no + t.string :address + t.integer :country_id + t.string :billing_address + + t.timestamps + end + + #legal documents + # create_table :documents do |t| + # t.integer :domain_id + # t.string :name + # t.status :document_type #if this is registration document or deletion document + + # t.timestamps + # end + + create_table :ns_sets do |t| + t.string :code #NSSID:STRING:OID + t.integer :registrar_id + t.string :auth_info #password for transferring between registrants + t.string :report_level + + #t.integer :technical_contact_id # reference to technical contact - + #does each ns_set have spearate technical contacts or can the contacts be inherited from the registrar? + + t.timestamps + end + + create_table :nameservers_ns_sets do |t| + t.integer :nameserver_id + t.integer :ns_set_id + end + + create_table :nameservers do |t| + t.string :name + t.string :ip + t.integer :ns_set_id + + t.timestamps + end + + #devise for login + #cancan for securing + #what to do with API users? + create_table :users do |t| + t.string :username + t.string :password + t.integer :role_id #can user have more than one role? + + t.timestamps + end + + create_table :roles do |t| + t.string :name + + t.timestamps + end + + create_table :rights_roles do |t| + t.integer :right_id + t.integer :role_id + end + + create_table :rights do |t| + t.string :code #LOG_IN, SEE_DOMAINS, etc + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..58ddc0139 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,122 @@ +# 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 that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20140616073945) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "addresses", force: true do |t| + t.integer "contact_id" + t.integer "country_id" + t.string "city" + t.string "address" + t.string "zip" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "contacts", force: true do |t| + t.string "code" + t.string "name" + t.string "type" + t.string "reg_no" + t.string "phone" + t.string "email" + t.string "fax" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "country_id", force: true do |t| + t.string "iso" + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "domains", force: true do |t| + t.string "name" + t.integer "registrar_id" + t.datetime "registered_at" + t.string "status" + t.datetime "valid_from" + t.datetime "valid_to" + t.integer "owner_contact_id" + t.integer "admin_contact_id" + t.integer "technical_contact_id" + t.integer "ns_set_id" + t.string "auth_info" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "nameservers", force: true do |t| + t.string "name" + t.string "ip" + t.integer "ns_set_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "nameservers_ns_sets", force: true do |t| + t.integer "nameserver_id" + t.integer "ns_set_id" + end + + create_table "ns_sets", force: true do |t| + t.string "code" + t.integer "registrar_id" + t.string "auth_info" + t.string "report_level" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "registrars", force: true do |t| + t.string "name" + t.string "reg_no" + t.string "vat_no" + t.string "address" + t.integer "country_id" + t.string "billing_address" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "rights", force: true do |t| + t.string "code" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "rights_roles", force: true do |t| + t.integer "right_id" + t.integer "role_id" + end + + create_table "roles", force: true do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "users", force: true do |t| + t.string "username" + t.string "password" + t.integer "role_id" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/spec/fabricators/domain_fabricator.rb b/spec/fabricators/domain_fabricator.rb new file mode 100644 index 000000000..7e1e244ba --- /dev/null +++ b/spec/fabricators/domain_fabricator.rb @@ -0,0 +1,3 @@ +Fabricator(:domain) do + name { "#{Faker::Internet.domain_word}.ee" } +end diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb new file mode 100644 index 000000000..eaa9603e2 --- /dev/null +++ b/spec/models/address_spec.rb @@ -0,0 +1,6 @@ +require "rails_helper" + +describe Address do + it { should belong_to(:contact) } + it { should belong_to(:country) } +end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb new file mode 100644 index 000000000..567c21c99 --- /dev/null +++ b/spec/models/contact_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe Contact do + it { should have_many(:addresses) } +end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb new file mode 100644 index 000000000..0030db26b --- /dev/null +++ b/spec/models/domain_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +describe Domain do + it { should belong_to(:registrar) } + it { should belong_to(:ns_set) } + it { should belong_to(:admin_contact) } + it { should belong_to(:owner_contact) } + it { should belong_to(:technical_contact) } + + it 'creates a resource' do + d = Fabricate(:domain) + expect(d.name).to_not be_nil + end +end diff --git a/spec/models/nameserver_spec.rb b/spec/models/nameserver_spec.rb new file mode 100644 index 000000000..3c8722fca --- /dev/null +++ b/spec/models/nameserver_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe Nameserver do + it { should have_and_belong_to_many(:ns_sets) } +end diff --git a/spec/models/ns_set_spec.rb b/spec/models/ns_set_spec.rb new file mode 100644 index 000000000..76a9762ac --- /dev/null +++ b/spec/models/ns_set_spec.rb @@ -0,0 +1,6 @@ +require "rails_helper" + +describe NsSet do + it { should belong_to(:registrar)} + it { should have_and_belong_to_many(:nameservers) } +end diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb new file mode 100644 index 000000000..e9ad976ad --- /dev/null +++ b/spec/models/registrar_spec.rb @@ -0,0 +1,7 @@ +require "rails_helper" + +describe Registrar do + it { should belong_to(:country) } + it { should have_many(:domains) } + it { should have_many(:ns_sets) } +end diff --git a/spec/models/right_spec.rb b/spec/models/right_spec.rb new file mode 100644 index 000000000..e3e8eecc7 --- /dev/null +++ b/spec/models/right_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe Right do + it { should have_and_belong_to_many(:roles) } +end diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb new file mode 100644 index 000000000..a8cd86e47 --- /dev/null +++ b/spec/models/role_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe Role do + it { should have_and_belong_to_many(:rights) } +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 000000000..322a3a67a --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe User do + it { should belong_to(:role) } +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 000000000..9274f2063 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,48 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require 'spec_helper' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'shoulda/matchers' + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # 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 + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 000000000..cfb18dcda --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,78 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause this +# file to always be loaded, without a need to explicitly require it in any files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, make a +# separate helper file that requires this one and then use it only in the specs +# that actually need it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # 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 + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + expectations.syntax = :expect + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + mocks.syntax = :expect + + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended. + mocks.verify_partial_doubles = true + end +=end +end