diff --git a/app/models/app.rb b/app/models/app.rb new file mode 100644 index 0000000..d3e15e6 --- /dev/null +++ b/app/models/app.rb @@ -0,0 +1,4 @@ +class App < ActiveRecord::Base + + validates :name, :package_name, presence: true +end diff --git a/app/models/batch_installation.rb b/app/models/batch_installation.rb new file mode 100644 index 0000000..4f7e556 --- /dev/null +++ b/app/models/batch_installation.rb @@ -0,0 +1,3 @@ +class BatchInstallation < ActiveRecord::Base + belongs_to :app +end diff --git a/app/models/installation.rb b/app/models/installation.rb new file mode 100644 index 0000000..d3d0a24 --- /dev/null +++ b/app/models/installation.rb @@ -0,0 +1,9 @@ +class Installation < ActiveRecord::Base + enum status: [:pushed, :downloaded, :cancelled, :installed] + + + + belongs_to :device + belongs_to :batch_installation + +end diff --git a/db/migrate/20151113123015_create_applications.rb b/db/migrate/20151113123015_create_applications.rb new file mode 100644 index 0000000..61cc006 --- /dev/null +++ b/db/migrate/20151113123015_create_applications.rb @@ -0,0 +1,10 @@ +class CreateApplications < ActiveRecord::Migration + def change + create_table :applications do |t| + t.string :name + t.string :package_name + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151113124226_rename_application_to_app.rb b/db/migrate/20151113124226_rename_application_to_app.rb new file mode 100644 index 0000000..7e503b0 --- /dev/null +++ b/db/migrate/20151113124226_rename_application_to_app.rb @@ -0,0 +1,5 @@ +class RenameApplicationToApp < ActiveRecord::Migration + def change + rename_table :applications, :apps + end +end diff --git a/db/migrate/20151113131647_create_batch_installations.rb b/db/migrate/20151113131647_create_batch_installations.rb new file mode 100644 index 0000000..b950f95 --- /dev/null +++ b/db/migrate/20151113131647_create_batch_installations.rb @@ -0,0 +1,9 @@ +class CreateBatchInstallations < ActiveRecord::Migration + def change + create_table :batch_installations do |t| + t.integer :app_id + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151113132152_create_installations.rb b/db/migrate/20151113132152_create_installations.rb new file mode 100644 index 0000000..6aaa6c9 --- /dev/null +++ b/db/migrate/20151113132152_create_installations.rb @@ -0,0 +1,11 @@ +class CreateInstallations < ActiveRecord::Migration + def change + create_table :installations do |t| + t.integer :device_id + t.integer :batch_installation_id + t.integer :status + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151113140645_change_status_data_type_from_string_to_integer_in_installation.rb b/db/migrate/20151113140645_change_status_data_type_from_string_to_integer_in_installation.rb new file mode 100644 index 0000000..f25cbd2 --- /dev/null +++ b/db/migrate/20151113140645_change_status_data_type_from_string_to_integer_in_installation.rb @@ -0,0 +1,5 @@ +class ChangeStatusDataTypeFromStringToIntegerInInstallation < ActiveRecord::Migration + def change + change_column :installations, :status, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 917add2..a56d2b8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151113095735) do +ActiveRecord::Schema.define(version: 20151113140645) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -49,6 +49,19 @@ ActiveRecord::Schema.define(version: 20151113095735) do add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree + create_table "apps", force: :cascade do |t| + t.string "name" + t.string "package_name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "batch_installations", force: :cascade do |t| + t.integer "app_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "devices", force: :cascade do |t| t.string "model" t.string "unique_id" @@ -69,5 +82,13 @@ ActiveRecord::Schema.define(version: 20151113095735) do add_index "heartbeats", ["device_id"], name: "index_heartbeats_on_device_id", using: :btree + create_table "installations", force: :cascade do |t| + t.integer "device_id" + t.integer "batch_installation_id" + t.integer "status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + add_foreign_key "heartbeats", "devices" end diff --git a/spec/factories/app.rb b/spec/factories/app.rb new file mode 100644 index 0000000..25f9e7c --- /dev/null +++ b/spec/factories/app.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :app do + name "My Ultimate Application" + package_name "my.ultimate.application" + end + +end diff --git a/spec/factories/batch_installations.rb b/spec/factories/batch_installations.rb new file mode 100644 index 0000000..5bb7557 --- /dev/null +++ b/spec/factories/batch_installations.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :batch_installation do + app_id 1 + end + +end diff --git a/spec/factories/installations.rb b/spec/factories/installations.rb new file mode 100644 index 0000000..8795f38 --- /dev/null +++ b/spec/factories/installations.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :installation do + device_id 1 + batch_installation_id 1 + status 1 + end + +end diff --git a/spec/models/app.rb b/spec/models/app.rb new file mode 100644 index 0000000..cc86d18 --- /dev/null +++ b/spec/models/app.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe App, type: :model do + pending "add some examples to (or delete) #{__FILE__}" + + let!(:app) { create(:app) } + + it { should validate_presence_of :name } + it { should validate_presence_of :package_name } + +end diff --git a/spec/models/batch_installation_spec.rb b/spec/models/batch_installation_spec.rb new file mode 100644 index 0000000..f46af1e --- /dev/null +++ b/spec/models/batch_installation_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe BatchInstallation, type: :model do + it {should belong_to(:app)} +end diff --git a/spec/models/installation_spec.rb b/spec/models/installation_spec.rb new file mode 100644 index 0000000..d2fb891 --- /dev/null +++ b/spec/models/installation_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +RSpec.describe Installation, type: :model do + it { should belong_to(:device) } + it { should belong_to(:batch_installation) } + + + + # Create Installation Model [Device ID, batch installation ID, status(Pushed, Downloaded, Cancelled, Installed)] + describe "Installation status" do + let!(:installation){FactoryGirl.create(:installation)} + it "Pushed" do + installation.pushed! + expect(installation.status).to eql Installation.statuses.keys[0] + end + it "Downloaded" do + installation.downloaded! + expect(installation.status).to eql Installation.statuses.keys[1] + end + it "Cancelled" do + installation.cancelled! + expect(installation.status).to eql Installation.statuses.keys[2] + end + + it "Installed" do + installation.installed! + expect(installation.status).to eql Installation.statuses.keys[3] + end + + end + +end