text:
require 'date'
require 'google/apis/core/base_service'
require 'google/apis/core/json_representation'
require 'google/apis/core/hashable'
require 'google/apis/errors'

module Google
  module Apis
    module ServicecontrolV1

      class AllocateInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AllocateQuotaRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AllocateQuotaResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AttributeValue
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Attributes
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AuditLog
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Auth
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AuthenticationInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AuthorizationInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CheckError
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CheckInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CheckRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CheckResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ConsumerInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Distribution
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Exemplar
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ExplicitBuckets
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ExponentialBuckets
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class FirstPartyPrincipal
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class HttpRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class LinearBuckets
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class LogEntry
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class LogEntryOperation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class LogEntrySourceLocation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class MetricValue
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class MetricValueSet
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Money
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Operation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class OrgPolicyViolationInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Peer
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class PolicyViolationInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class QuotaError
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class QuotaInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class QuotaOperation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class QuotaProperties
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ReportError
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ReportRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ReportResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Request
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class RequestMetadata
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Resource
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ResourceInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ResourceLocation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ServiceAccountDelegationInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class SpanContext
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Status
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ThirdPartyPrincipal
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class TraceSpan
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class TruncatableString
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class V1HttpRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class V1LogEntry
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class V1LogEntryOperation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class V1LogEntrySourceLocation
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ViolationInfo
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class AllocateInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :unused_arguments, as: 'unusedArguments'
        end
      end

      class AllocateQuotaRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :allocate_operation, as: 'allocateOperation', class: Google::Apis::ServicecontrolV1::QuotaOperation, decorator: Google::Apis::ServicecontrolV1::QuotaOperation::Representation

          property :service_config_id, as: 'serviceConfigId'
        end
      end

      class AllocateQuotaResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :allocate_errors, as: 'allocateErrors', class: Google::Apis::ServicecontrolV1::QuotaError, decorator: Google::Apis::ServicecontrolV1::QuotaError::Representation

          property :allocate_info, as: 'allocateInfo', class: Google::Apis::ServicecontrolV1::AllocateInfo, decorator: Google::Apis::ServicecontrolV1::AllocateInfo::Representation

          property :operation_id, as: 'operationId'
          collection :quota_metrics, as: 'quotaMetrics', class: Google::Apis::ServicecontrolV1::MetricValueSet, decorator: Google::Apis::ServicecontrolV1::MetricValueSet::Representation

          property :service_config_id, as: 'serviceConfigId'
        end
      end

      class AttributeValue
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :bool_value, as: 'boolValue'
          property :int_value, :numeric_string => true, as: 'intValue'
          property :string_value, as: 'stringValue', class: Google::Apis::ServicecontrolV1::TruncatableString, decorator: Google::Apis::ServicecontrolV1::TruncatableString::Representation

        end
      end

      class Attributes
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          hash :attribute_map, as: 'attributeMap', class: Google::Apis::ServicecontrolV1::AttributeValue, decorator: Google::Apis::ServicecontrolV1::AttributeValue::Representation

          property :dropped_attributes_count, as: 'droppedAttributesCount'
        end
      end

      class AuditLog
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :authentication_info, as: 'authenticationInfo', class: Google::Apis::ServicecontrolV1::AuthenticationInfo, decorator: Google::Apis::ServicecontrolV1::AuthenticationInfo::Representation

          collection :authorization_info, as: 'authorizationInfo', class: Google::Apis::ServicecontrolV1::AuthorizationInfo, decorator: Google::Apis::ServicecontrolV1::AuthorizationInfo::Representation

          hash :metadata, as: 'metadata'
          property :method_name, as: 'methodName'
          property :num_response_items, :numeric_string => true, as: 'numResponseItems'
          property :policy_violation_info, as: 'policyViolationInfo', class: Google::Apis::ServicecontrolV1::PolicyViolationInfo, decorator: Google::Apis::ServicecontrolV1::PolicyViolationInfo::Representation

          hash :request, as: 'request'
          property :request_metadata, as: 'requestMetadata', class: Google::Apis::ServicecontrolV1::RequestMetadata, decorator: Google::Apis::ServicecontrolV1::RequestMetadata::Representation

          property :resource_location, as: 'resourceLocation', class: Google::Apis::ServicecontrolV1::ResourceLocation, decorator: Google::Apis::ServicecontrolV1::ResourceLocation::Representation

          property :resource_name, as: 'resourceName'
          hash :resource_original_state, as: 'resourceOriginalState'
          hash :response, as: 'response'
          hash :service_data, as: 'serviceData'
          property :service_name, as: 'serviceName'
          property :status, as: 'status', class: Google::Apis::ServicecontrolV1::Status, decorator: Google::Apis::ServicecontrolV1::Status::Representation

        end
      end

      class Auth
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :access_levels, as: 'accessLevels'
          collection :audiences, as: 'audiences'
          hash :claims, as: 'claims'
          property :presenter, as: 'presenter'
          property :principal, as: 'principal'
        end
      end

      class AuthenticationInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :authority_selector, as: 'authoritySelector'
          property :principal_email, as: 'principalEmail'
          property :principal_subject, as: 'principalSubject'
          collection :service_account_delegation_info, as: 'serviceAccountDelegationInfo', class: Google::Apis::ServicecontrolV1::ServiceAccountDelegationInfo, decorator: Google::Apis::ServicecontrolV1::ServiceAccountDelegationInfo::Representation

          property :service_account_key_name, as: 'serviceAccountKeyName'
          hash :third_party_principal, as: 'thirdPartyPrincipal'
        end
      end

      class AuthorizationInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :granted, as: 'granted'
          property :permission, as: 'permission'
          property :resource, as: 'resource'
          property :resource_attributes, as: 'resourceAttributes', class: Google::Apis::ServicecontrolV1::Resource, decorator: Google::Apis::ServicecontrolV1::Resource::Representation

        end
      end

      class CheckError
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :code, as: 'code'
          property :detail, as: 'detail'
          property :status, as: 'status', class: Google::Apis::ServicecontrolV1::Status, decorator: Google::Apis::ServicecontrolV1::Status::Representation

          property :subject, as: 'subject'
        end
      end

      class CheckInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :consumer_info, as: 'consumerInfo', class: Google::Apis::ServicecontrolV1::ConsumerInfo, decorator: Google::Apis::ServicecontrolV1::ConsumerInfo::Representation

          collection :unused_arguments, as: 'unusedArguments'
        end
      end

      class CheckRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :operation, as: 'operation', class: Google::Apis::ServicecontrolV1::Operation, decorator: Google::Apis::ServicecontrolV1::Operation::Representation

          property :request_project_settings, as: 'requestProjectSettings'
          property :service_config_id, as: 'serviceConfigId'
          property :skip_activation_check, as: 'skipActivationCheck'
        end
      end

      class CheckResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :check_errors, as: 'checkErrors', class: Google::Apis::ServicecontrolV1::CheckError, decorator: Google::Apis::ServicecontrolV1::CheckError::Representation

          property :check_info, as: 'checkInfo', class: Google::Apis::ServicecontrolV1::CheckInfo, decorator: Google::Apis::ServicecontrolV1::CheckInfo::Representation

          property :operation_id, as: 'operationId'
          property :quota_info, as: 'quotaInfo', class: Google::Apis::ServicecontrolV1::QuotaInfo, decorator: Google::Apis::ServicecontrolV1::QuotaInfo::Representation

          property :service_config_id, as: 'serviceConfigId'
          property :service_rollout_id, as: 'serviceRolloutId'
        end
      end

      class ConsumerInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :consumer_number, :numeric_string => true, as: 'consumerNumber'
          property :project_number, :numeric_string => true, as: 'projectNumber'
          property :type, as: 'type'
        end
      end

      class Distribution
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :bucket_counts, as: 'bucketCounts'
          property :count, :numeric_string => true, as: 'count'
          collection :exemplars, as: 'exemplars', class: Google::Apis::ServicecontrolV1::Exemplar, decorator: Google::Apis::ServicecontrolV1::Exemplar::Representation

          property :explicit_buckets, as: 'explicitBuckets', class: Google::Apis::ServicecontrolV1::ExplicitBuckets, decorator: Google::Apis::ServicecontrolV1::ExplicitBuckets::Representation

          property :exponential_buckets, as: 'exponentialBuckets', class: Google::Apis::ServicecontrolV1::ExponentialBuckets, decorator: Google::Apis::ServicecontrolV1::ExponentialBuckets::Representation

          property :linear_buckets, as: 'linearBuckets', class: Google::Apis::ServicecontrolV1::LinearBuckets, decorator: Google::Apis::ServicecontrolV1::LinearBuckets::Representation

          property :maximum, as: 'maximum'
          property :mean, as: 'mean'
          property :minimum, as: 'minimum'
          property :sum_of_squared_deviation, as: 'sumOfSquaredDeviation'
        end
      end

      class Exemplar
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :attachments, as: 'attachments'
          property :timestamp, as: 'timestamp'
          property :value, as: 'value'
        end
      end

      class ExplicitBuckets
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :bounds, as: 'bounds'
        end
      end

      class ExponentialBuckets
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :growth_factor, as: 'growthFactor'
          property :num_finite_buckets, as: 'numFiniteBuckets'
          property :scale, as: 'scale'
        end
      end

      class FirstPartyPrincipal
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :principal_email, as: 'principalEmail'
          hash :service_metadata, as: 'serviceMetadata'
        end
      end

      class HttpRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :cache_fill_bytes, :numeric_string => true, as: 'cacheFillBytes'
          property :cache_hit, as: 'cacheHit'
          property :cache_lookup, as: 'cacheLookup'
          property :cache_validated_with_origin_server, as: 'cacheValidatedWithOriginServer'
          property :latency, as: 'latency'
          property :protocol, as: 'protocol'
          property :referer, as: 'referer'
          property :remote_ip, as: 'remoteIp'
          property :request_method, as: 'requestMethod'
          property :request_size, :numeric_string => true, as: 'requestSize'
          property :request_url, as: 'requestUrl'
          property :response_size, :numeric_string => true, as: 'responseSize'
          property :server_ip, as: 'serverIp'
          property :status, as: 'status'
          property :user_agent, as: 'userAgent'
        end
      end

      class LinearBuckets
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :num_finite_buckets, as: 'numFiniteBuckets'
          property :offset, as: 'offset'
          property :width, as: 'width'
        end
      end

      class LogEntry
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :http_request, as: 'httpRequest', class: Google::Apis::ServicecontrolV1::HttpRequest, decorator: Google::Apis::ServicecontrolV1::HttpRequest::Representation

          property :insert_id, as: 'insertId'
          hash :labels, as: 'labels'
          property :name, as: 'name'
          property :operation, as: 'operation', class: Google::Apis::ServicecontrolV1::LogEntryOperation, decorator: Google::Apis::ServicecontrolV1::LogEntryOperation::Representation

          hash :proto_payload, as: 'protoPayload'
          property :severity, as: 'severity'
          property :source_location, as: 'sourceLocation', class: Google::Apis::ServicecontrolV1::LogEntrySourceLocation, decorator: Google::Apis::ServicecontrolV1::LogEntrySourceLocation::Representation

          hash :struct_payload, as: 'structPayload'
          property :text_payload, as: 'textPayload'
          property :timestamp, as: 'timestamp'
          property :trace, as: 'trace'
        end
      end

      class LogEntryOperation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :first, as: 'first'
          property :id, as: 'id'
          property :last, as: 'last'
          property :producer, as: 'producer'
        end
      end

      class LogEntrySourceLocation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :file, as: 'file'
          property :function, as: 'function'
          property :line, :numeric_string => true, as: 'line'
        end
      end

      class MetricValue
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :bool_value, as: 'boolValue'
          property :distribution_value, as: 'distributionValue', class: Google::Apis::ServicecontrolV1::Distribution, decorator: Google::Apis::ServicecontrolV1::Distribution::Representation

          property :double_value, as: 'doubleValue'
          property :end_time, as: 'endTime'
          property :int64_value, :numeric_string => true, as: 'int64Value'
          hash :labels, as: 'labels'
          property :money_value, as: 'moneyValue', class: Google::Apis::ServicecontrolV1::Money, decorator: Google::Apis::ServicecontrolV1::Money::Representation

          property :start_time, as: 'startTime'
          property :string_value, as: 'stringValue'
        end
      end

      class MetricValueSet
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :metric_name, as: 'metricName'
          collection :metric_values, as: 'metricValues', class: Google::Apis::ServicecontrolV1::MetricValue, decorator: Google::Apis::ServicecontrolV1::MetricValue::Representation

        end
      end

      class Money
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :currency_code, as: 'currencyCode'
          property :nanos, as: 'nanos'
          property :units, :numeric_string => true, as: 'units'
        end
      end

      class Operation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :consumer_id, as: 'consumerId'
          property :end_time, as: 'endTime'
          property :importance, as: 'importance'
          hash :labels, as: 'labels'
          collection :log_entries, as: 'logEntries', class: Google::Apis::ServicecontrolV1::LogEntry, decorator: Google::Apis::ServicecontrolV1::LogEntry::Representation

          collection :metric_value_sets, as: 'metricValueSets', class: Google::Apis::ServicecontrolV1::MetricValueSet, decorator: Google::Apis::ServicecontrolV1::MetricValueSet::Representation

          property :operation_id, as: 'operationId'
          property :operation_name, as: 'operationName'
          property :quota_properties, as: 'quotaProperties', class: Google::Apis::ServicecontrolV1::QuotaProperties, decorator: Google::Apis::ServicecontrolV1::QuotaProperties::Representation

          collection :resources, as: 'resources', class: Google::Apis::ServicecontrolV1::ResourceInfo, decorator: Google::Apis::ServicecontrolV1::ResourceInfo::Representation

          property :start_time, as: 'startTime'
          collection :trace_spans, as: 'traceSpans', class: Google::Apis::ServicecontrolV1::TraceSpan, decorator: Google::Apis::ServicecontrolV1::TraceSpan::Representation

          hash :user_labels, as: 'userLabels'
        end
      end

      class OrgPolicyViolationInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          hash :payload, as: 'payload'
          hash :resource_tags, as: 'resourceTags'
          property :resource_type, as: 'resourceType'
          collection :violation_info, as: 'violationInfo', class: Google::Apis::ServicecontrolV1::ViolationInfo, decorator: Google::Apis::ServicecontrolV1::ViolationInfo::Representation

        end
      end

      class Peer
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :ip, as: 'ip'
          hash :labels, as: 'labels'
          property :port, :numeric_string => true, as: 'port'
          property :principal, as: 'principal'
          property :region_code, as: 'regionCode'
        end
      end

      class PolicyViolationInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :org_policy_violation_info, as: 'orgPolicyViolationInfo', class: Google::Apis::ServicecontrolV1::OrgPolicyViolationInfo, decorator: Google::Apis::ServicecontrolV1::OrgPolicyViolationInfo::Representation

        end
      end

      class QuotaError
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :code, as: 'code'
          property :description, as: 'description'
          property :status, as: 'status', class: Google::Apis::ServicecontrolV1::Status, decorator: Google::Apis::ServicecontrolV1::Status::Representation

          property :subject, as: 'subject'
        end
      end

      class QuotaInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :limit_exceeded, as: 'limitExceeded'
          hash :quota_consumed, as: 'quotaConsumed'
          collection :quota_metrics, as: 'quotaMetrics', class: Google::Apis::ServicecontrolV1::MetricValueSet, decorator: Google::Apis::ServicecontrolV1::MetricValueSet::Representation

        end
      end

      class QuotaOperation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :consumer_id, as: 'consumerId'
          hash :labels, as: 'labels'
          property :method_name, as: 'methodName'
          property :operation_id, as: 'operationId'
          collection :quota_metrics, as: 'quotaMetrics', class: Google::Apis::ServicecontrolV1::MetricValueSet, decorator: Google::Apis::ServicecontrolV1::MetricValueSet::Representation

          property :quota_mode, as: 'quotaMode'
        end
      end

      class QuotaProperties
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :quota_mode, as: 'quotaMode'
        end
      end

      class ReportError
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :operation_id, as: 'operationId'
          property :status, as: 'status', class: Google::Apis::ServicecontrolV1::Status, decorator: Google::Apis::ServicecontrolV1::Status::Representation

        end
      end

      class ReportRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :operations, as: 'operations', class: Google::Apis::ServicecontrolV1::Operation, decorator: Google::Apis::ServicecontrolV1::Operation::Representation

          property :service_config_id, as: 'serviceConfigId'
        end
      end

      class ReportResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :report_errors, as: 'reportErrors', class: Google::Apis::ServicecontrolV1::ReportError, decorator: Google::Apis::ServicecontrolV1::ReportError::Representation

          property :service_config_id, as: 'serviceConfigId'
          property :service_rollout_id, as: 'serviceRolloutId'
        end
      end

      class Request
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :auth, as: 'auth', class: Google::Apis::ServicecontrolV1::Auth, decorator: Google::Apis::ServicecontrolV1::Auth::Representation

          hash :headers, as: 'headers'
          property :host, as: 'host'
          property :id, as: 'id'
          property :method_prop, as: 'method'
          property :path, as: 'path'
          property :protocol, as: 'protocol'
          property :query, as: 'query'
          property :reason, as: 'reason'
          property :scheme, as: 'scheme'
          property :size, :numeric_string => true, as: 'size'
          property :time, as: 'time'
        end
      end

      class RequestMetadata
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :caller_ip, as: 'callerIp'
          property :caller_network, as: 'callerNetwork'
          property :caller_supplied_user_agent, as: 'callerSuppliedUserAgent'
          property :destination_attributes, as: 'destinationAttributes', class: Google::Apis::ServicecontrolV1::Peer, decorator: Google::Apis::ServicecontrolV1::Peer::Representation

          property :request_attributes, as: 'requestAttributes', class: Google::Apis::ServicecontrolV1::Request, decorator: Google::Apis::ServicecontrolV1::Request::Representation

        end
      end

      class Resource
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          hash :annotations, as: 'annotations'
          property :create_time, as: 'createTime'
          property :delete_time, as: 'deleteTime'
          property :display_name, as: 'displayName'
          property :etag, as: 'etag'
          hash :labels, as: 'labels'
          property :location, as: 'location'
          property :name, as: 'name'
          property :service, as: 'service'
          property :type, as: 'type'
          property :uid, as: 'uid'
          property :update_time, as: 'updateTime'
        end
      end

      class ResourceInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :permission, as: 'permission'
          property :resource_container, as: 'resourceContainer'
          property :resource_location, as: 'resourceLocation'
          property :resource_name, as: 'resourceName'
        end
      end

      class ResourceLocation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :current_locations, as: 'currentLocations'
          collection :original_locations, as: 'originalLocations'
        end
      end

      class ServiceAccountDelegationInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :first_party_principal, as: 'firstPartyPrincipal', class: Google::Apis::ServicecontrolV1::FirstPartyPrincipal, decorator: Google::Apis::ServicecontrolV1::FirstPartyPrincipal::Representation

          property :principal_subject, as: 'principalSubject'
          property :third_party_principal, as: 'thirdPartyPrincipal', class: Google::Apis::ServicecontrolV1::ThirdPartyPrincipal, decorator: Google::Apis::ServicecontrolV1::ThirdPartyPrincipal::Representation

        end
      end

      class SpanContext
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :span_name, as: 'spanName'
        end
      end

      class Status
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :code, as: 'code'
          collection :details, as: 'details'
          property :message, as: 'message'
        end
      end

      class ThirdPartyPrincipal
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          hash :third_party_claims, as: 'thirdPartyClaims'
        end
      end

      class TraceSpan
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :attributes, as: 'attributes', class: Google::Apis::ServicecontrolV1::Attributes, decorator: Google::Apis::ServicecontrolV1::Attributes::Representation

          property :child_span_count, as: 'childSpanCount'
          property :display_name, as: 'displayName', class: Google::Apis::ServicecontrolV1::TruncatableString, decorator: Google::Apis::ServicecontrolV1::TruncatableString::Representation

          property :end_time, as: 'endTime'
          property :name, as: 'name'
          property :parent_span_id, as: 'parentSpanId'
          property :same_process_as_parent_span, as: 'sameProcessAsParentSpan'
          property :span_id, as: 'spanId'
          property :span_kind, as: 'spanKind'
          property :start_time, as: 'startTime'
          property :status, as: 'status', class: Google::Apis::ServicecontrolV1::Status, decorator: Google::Apis::ServicecontrolV1::Status::Representation

        end
      end

      class TruncatableString
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :truncated_byte_count, as: 'truncatedByteCount'
          property :value, as: 'value'
        end
      end

      class V1HttpRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :cache_fill_bytes, :numeric_string => true, as: 'cacheFillBytes'
          property :cache_hit, as: 'cacheHit'
          property :cache_lookup, as: 'cacheLookup'
          property :cache_validated_with_origin_server, as: 'cacheValidatedWithOriginServer'
          property :latency, as: 'latency'
          property :protocol, as: 'protocol'
          property :referer, as: 'referer'
          property :remote_ip, as: 'remoteIp'
          property :request_method, as: 'requestMethod'
          property :request_size, :numeric_string => true, as: 'requestSize'
          property :request_url, as: 'requestUrl'
          property :response_size, :numeric_string => true, as: 'responseSize'
          property :server_ip, as: 'serverIp'
          property :status, as: 'status'
          property :user_agent, as: 'userAgent'
        end
      end

      class V1LogEntry
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :http_request, as: 'httpRequest', class: Google::Apis::ServicecontrolV1::V1HttpRequest, decorator: Google::Apis::ServicecontrolV1::V1HttpRequest::Representation

          property :insert_id, as: 'insertId'
          hash :labels, as: 'labels'
          hash :monitored_resource_labels, as: 'monitoredResourceLabels'
          property :name, as: 'name'
          property :operation, as: 'operation', class: Google::Apis::ServicecontrolV1::V1LogEntryOperation, decorator: Google::Apis::ServicecontrolV1::V1LogEntryOperation::Representation

          hash :proto_payload, as: 'protoPayload'
          property :severity, as: 'severity'
          property :source_location, as: 'sourceLocation', class: Google::Apis::ServicecontrolV1::V1LogEntrySourceLocation, decorator: Google::Apis::ServicecontrolV1::V1LogEntrySourceLocation::Representation

          hash :struct_payload, as: 'structPayload'
          property :text_payload, as: 'textPayload'
          property :timestamp, as: 'timestamp'
          property :trace, as: 'trace'
        end
      end

      class V1LogEntryOperation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :first, as: 'first'
          property :id, as: 'id'
          property :last, as: 'last'
          property :producer, as: 'producer'
        end
      end

      class V1LogEntrySourceLocation
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :file, as: 'file'
          property :function, as: 'function'
          property :line, :numeric_string => true, as: 'line'
        end
      end

      class ViolationInfo
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :checked_value, as: 'checkedValue'
          property :constraint, as: 'constraint'
          property :error_message, as: 'errorMessage'
          property :policy_type, as: 'policyType'
        end
      end
    end
  end
end


text:
describe "GET /people/:person_id/fans", type: :request do
  let(:person) { create(:person) }
  let!(:user) { create(:registered_user) }
  let!(:person_favorite) { create(:person_favorite, user: user, person: person) }

  it "アクセスできること" do
    get "/people/#{person.id}/fans"

    expect(response.status).to eq(200)
    expect(response.body).to include(person.name)
    expect(response.body).to include(user.profile.name)
  end
end

redpajama_set_name: RedPajamaGithub


text:
jQuery( document ).ready( function( $ ) {
  /* Clear the initial password suggestion from WordPress */
  $( '#resetpassform input[name=\'pass1\']' ).attr( 'data-pw', '' )
  $('#resetpassform #pass1').val('');
  $('#resetpassform #pass1-text').val('');
  /* Change button text */
  $('#resetpassform #wp-submit').val(objectL10n.buttonLabel);
});


text:
        Ai votat și ai primit o bere gratuită! Mergi la voluntarii noștri pentru a o putea lua!

            {{ concurente[i]?.display_name }}

                {{ concurente[i]?.display_name }}close

{{ concurente[i]?.description }}

Voteaza

            {{ concurenti[i]?.display_name }}

                {{ concurenti[i]?.display_name }}close

{{ concurenti[i]?.description }}

Voteaza


text:
require 'test_helper'

class AssaysControllerTest < ActionController::TestCase

  fixtures :all

  include AuthenticatedTestHelper
  include RestTestCases
  include RdfTestCases
  include FunctionalAuthorizationTests

  def setup
    login_as(:quentin)
  end

  def rest_api_test_object
    @object=Factory(:experimental_assay, :policy => Factory(:public_policy))
  end

  test "modelling assay validates with schema" do
    df = Factory(:data_file,:contributor=>User.current_user.person)
    a = Factory(:modelling_assay,:contributor=>User.current_user.person)
    disable_authorization_checks do
      a.relate(df)
      a.reload
    end

    User.with_current_user(a.study.investigation.contributor) { a.study.investigation.projects << Factory(:project) }
    assert_difference('ActivityLog.count') do
      get :show, :id=>a, :format=>"xml"
    end

    assert_response :success

    validate_xml_against_schema(@response.body)
  end

  test "check SOP and DataFile drop down contents" do
    user = Factory :user
    project=user.person.projects.first
    login_as user
    sop = Factory :sop, :contributor=>user.person,:project_ids=>[project.id]
    data_file = Factory :data_file, :contributor=>user.person,:project_ids=>[project.id]
    get :new, :class=>"experimental"
    assert_response :success

    assert_select "select#possible_data_files" do
      assert_select "option[value=?]",data_file.id,:text=>/#{data_file.title}/
      assert_select "option",:text=>/#{sop.title}/,:count=>0
    end

    assert_select "select#possible_sops" do
      assert_select "option[value=?]",sop.id,:text=>/#{sop.title}/
      assert_select "option",:text=>/#{data_file.title}/,:count=>0
    end
  end

  test "index includes modelling validates with schema" do
    get :index, :page=>"all", :format=>"xml"
    assert_response :success
    assays=assigns(:assays)
    assert assays.include?(assays(:modelling_assay_with_data_and_relationship)), "This test is invalid as the list should include the modelling assay"

    validate_xml_against_schema(@response.body)
  end

  test "shouldn't show unauthorized assays" do
    login_as Factory(:user)
    hidden = Factory(:experimental_assay, :policy => Factory(:private_policy)) #ensure at least one hidden assay exists
    get :index, :page=>"all", :format=>"xml"
    assert_response :success
    assert_equal assigns(:assays).sort_by(&:id), Assay.authorize_asset_collection(assigns(:assays), "view", users(:aaron)).sort_by(&:id), "#{t('assays.assay').downcase.pluralize} haven't been authorized"
    assert !assigns(:assays).include?(hidden)
  end

  def test_title
    get :index
    assert_select "title", :text=>/#{Seek::Config.application_title} #{I18n.t('assays.assay')}s.*/i, :count=>1
  end

  test "should show index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:assays)
  end

  test "should show draggable icon in index" do
    get :index
    assert_response :success
    assays = assigns(:assays)
    first_assay = assays.first
    assert_not_nil first_assay
    assert_select "a[id*=?]", /drag_Assay_#{first_assay.id}/
  end

  test "should show index in xml" do
    get :index
    assert_response :success
    assert_not_nil assigns(:assays)
  end

  test "should update assay with new version of same sop" do
    login_as(:model_owner)
    assay=assays(:metabolomics_assay)
    timestamp=assay.updated_at

    sop = sops(:sop_with_all_sysmo_users_policy)
    assert !assay.sops.include?(sop.latest_version)
    assert_difference('ActivityLog.count') do
      put :update, :id=>assay, :assay_sop_ids=>[sop.id], :assay=>{}, :assay_sample_ids=>[Factory(:sample).id]
    end

    assert_redirected_to assay_path(assay)
    assert assigns(:assay)

    assay.reload
    stored_sop = assay.assay_assets.detect { |aa| aa.asset_id=sop.id }.versioned_asset
    assert_equal sop.version, stored_sop.version

    login_as sop.contributor
    sop.save_as_new_version
    login_as(:model_owner)

    assert_difference('ActivityLog.count') do
      put :update, :id=>assay, :assay_sop_ids=>[sop.id], :assay=>{}, :assay_sample_ids=>[Factory(:sample).id]
    end

    assay.reload
    stored_sop = assay.assay_assets.detect { |aa| aa.asset_id=sop.id }.versioned_asset
    assert_equal sop.version, stored_sop.version

  end

  test "should update timestamp when associating sop" do
    login_as(:model_owner)
    assay=assays(:metabolomics_assay)
    timestamp=assay.updated_at

    sop = sops(:sop_with_all_sysmo_users_policy)
    assert !assay.sops.include?(sop.latest_version)
    sleep(1)
    assert_difference('ActivityLog.count') do
      put :update, :id=>assay, :assay_sop_ids=>[sop.id], :assay=>{}, :assay_sample_ids=>[Factory(:sample).id]
    end

    assert_redirected_to assay_path(assay)
    assert assigns(:assay)
    updated_assay=Assay.find(assay.id)
    assert updated_assay.sops.include?(sop.latest_version)
    assert_not_equal timestamp, updated_assay.updated_at

  end

  test "should update timestamp when associating datafile" do
    login_as(:model_owner)
    assay=assays(:metabolomics_assay)
    timestamp=assay.updated_at

    df = data_files(:downloadable_data_file)
    assert !assay.data_files.include?(df.latest_version)
    sleep(1)
    assert_difference('ActivityLog.count') do
      put :update, :id=>assay, :data_file_ids=>["#{df.id},Test data"], :assay=>{}, :assay_sample_ids=>[Factory(:sample).id]
    end

    assert_redirected_to assay_path(assay)
    assert assigns(:assay)
    updated_assay=Assay.find(assay.id)
    assert updated_assay.data_files.include?(df.latest_version)
    assert_not_equal timestamp, updated_assay.updated_at
  end

  test "should update timestamp when associating model" do
    login_as(:model_owner)
    assay=assays(:metabolomics_assay)
    timestamp=assay.updated_at

    model = models(:teusink)
    assert !assay.models.include?(model.latest_version)
    sleep(1)
    assert_difference('ActivityLog.count') do
      put :update, :id=>assay, :model_ids=>[model.id], :assay=>{}, :assay_sample_ids=>[Factory(:sample).id]
    end

    assert_redirected_to assay_path(assay)
    assert assigns(:assay)
    updated_assay=Assay.find(assay.id)
    assert updated_assay.models.include?(model.latest_version)
    assert_not_equal timestamp, updated_assay.updated_at
  end

  test "should show item" do
    assay = Factory(:experimental_assay,:policy=>Factory(:public_policy),
                    :assay_type_label=>"Metabolomics",
                    :technology_type_label=>"Gas chromatography")
    assert_difference('ActivityLog.count') do
      get :show, :id=>assay.id
    end

    assert_response :success

    assert_not_nil assigns(:assay)

    assert_select "p#assay_type", :text=>/Metabolomics/, :count=>1
    assert_select "p#technology_type", :text=>/Gas chromatography/, :count=>1
  end

  test "should not show tagging when not logged in" do
    logout
    public_assay = Factory(:experimental_assay, :policy => Factory(:public_policy))
    get :show, :id=>public_assay
    assert_response :success
    assert_select "div#tags_box", :count=>0
  end

  test "should show modelling assay" do
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:modelling_assay_with_data_and_relationship)
    end

    assert_response :success
    assert_not_nil assigns(:assay)
    assert_equal assigns(:assay), assays(:modelling_assay_with_data_and_relationship)
  end

  test "should show new" do
    get :new
    assert_response :success
    assert_not_nil assigns(:assay)
    assert_nil assigns(:assay).study
  end

  test "should show new with study when id provided" do
    s=studies(:metabolomics_study)
    get :new, :study_id=>s
    assert_response :success
    assert_not_nil assigns(:assay)
    assert_equal s, assigns(:assay).study
  end

  test "should show item with no study" do
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:assay_with_no_study_or_files)
    end

    assert_response :success
    assert_not_nil assigns(:assay)
  end

  test "should update with study" do
    login_as(:model_owner)
    a=assays(:assay_with_no_study_or_files)
    s=studies(:metabolomics_study)
    assert_difference('ActivityLog.count') do
      put :update, :id=>a, :assay=>{:study_id=>s}, :assay_sample_ids=>[Factory(:sample).id]
    end

    assert_redirected_to assay_path(a)
    assert assigns(:assay)
    assert_not_nil assigns(:assay).study
    assert_equal s, assigns(:assay).study
  end

  test "should create experimental assay with or without sample" do
    assert_difference('ActivityLog.count') do
      assert_difference("Assay.count") do
        post :create, :assay => {:title => "test",
                                 :study_id => studies(:metabolomics_study).id,
                                 :assay_class_id => assay_classes(:experimental_assay_class).id}
      end
    end
    a=assigns(:assay)
    assert a.samples.empty?

    sample = Factory(:sample)
    assert_difference('ActivityLog.count') do
      assert_difference("Assay.count") do
        post :create, :assay => {:title => "test",
                                 :study_id => studies(:metabolomics_study).id,
                                 :assay_class_id => assay_classes(:experimental_assay_class).id,
                                 :sample_ids => [sample.id]
        }

      end
    end
    a=assigns(:assay)
    assert_equal User.current_user.person, a.owner
    assert_redirected_to assay_path(a)
    assert_equal [sample], a.samples
  end

  test "should update assay with strains and organisms and sample" do
    assay = Factory(:assay,:contributor=>User.current_user.person)
    assert_empty assay.organisms
    assert_empty assay.strains
    assert_empty assay.samples

    organism = Factory(:organism,:title=>"Frog")
    strain = Factory(:strain, :title=>"UUU", :organism=>organism)
    sample = Factory(:sample)

    assert_difference("AssayOrganism.count") do
      put :update, :id=>assay.id,:assay => {:title => "test",
                                            :sample_ids => [sample.id]},
                        :assay_organism_ids => [organism.id,strain.title, strain.id, ""].join(",")

    end
    assert_response :success
    assay = assigns(:assay)
    assert_include assay.organisms,organism
    assert_include assay.strains,strain
    assert_include assay.samples,sample
  end

  test "should create experimental assay with/without organisms" do

    sample = Factory(:sample)
    assert_difference("Assay.count") do
      post :create, :assay=>{:title=>"test",
                             :technology_type_uri=>"http://www.mygrid.org.uk/ontology/JERMOntology#Gas_chromatography",
                             :assay_type_uri=>"http://www.mygrid.org.uk/ontology/JERMOntology#Metabolomics",
                             :study_id=>studies(:metabolomics_study).id,
                             :assay_class_id=>assay_classes(:experimental_assay_class).id,
                             :sample_ids => [sample]}
    end
    assay = assigns(:assay)
    refute_nil assay
    assert assay.organisms.empty?
    assert assay.strains.empty?
    assert_include assay.samples,sample

    organism = Factory(:organism,:title=>"Frog")
    strain = Factory(:strain, :title=>"UUU", :organism=>organism)
    growth_type = Factory(:culture_growth_type, :title=>"ssdfkhsdfkh")
    assert_difference("Assay.count") do
      post :create, :assay=>{:title=>"test",
                             :technology_type_uri=>"http://www.mygrid.org.uk/ontology/JERMOntology#Gas_chromatography",
                             :assay_type_uri=>"http://www.mygrid.org.uk/ontology/JERMOntology#Metabolomics",
                             :study_id=>studies(:metabolomics_study).id,
                             :assay_class_id=>assay_classes(:experimental_assay_class).id,
                             :sample_ids => [Factory(:sample)]},
                             :assay_organism_ids => [organism.id,strain.title, strain.id, growth_type.title].join(",")
    end
    a=assigns(:assay)
    assert_redirected_to assay_path(a)
    assert_include a.organisms, organism
    assert_include a.strains,strain
    assert_equal 1,a.assay_organisms.count
    assert_equal growth_type,a.assay_organisms.last.culture_growth_type

    #create assay with samples and organisms, but not strain
    sample = Factory(:sample)
    assert_difference('ActivityLog.count') do
      assert_difference("Assay.count") do
        post :create,:assay=>{:title=>"test",
                              :study_id=>studies(:metabolomics_study).id,
                              :assay_class_id=>assay_classes(:experimental_assay_class).id,
                              :sample_ids=>[sample.id]
        },:assay_organism_ids=>[organism.id.to_s,"","",""].join(",")
      end
    end
    a=assigns(:assay)
    assert_include a.organisms, organism
    assert_include a.samples,sample
    assert_empty a.strains
    assert_redirected_to assay_path(a)
  end

  test "should create modelling assay with/without organisms" do

    assert_difference("Assay.count") do
      post :create, :assay=>{:title=>"test",
                             :study_id=>studies(:metabolomics_study).id,
                             :assay_class_id=>assay_classes(:modelling_assay_class).id}
    end

    assay = assigns(:assay)
    refute_nil assay
    assert assay.organisms.empty?
    assert assay.strains.empty?

    organism = Factory(:organism,:title=>"Frog")
    strain = Factory(:strain, :title=>"UUU", :organism=>organism)
    growth_type = Factory(:culture_growth_type, :title=>"batch")
    assert_difference("Assay.count") do
      post :create, :assay=>{:title=>"test",
                             :study_id=>studies(:metabolomics_study).id,
                             :assay_class_id=>assay_classes(:modelling_assay_class).id},
           :assay_organism_ids => [organism.id, strain.title,strain.id, growth_type.title].join(",")
    end
    a=assigns(:assay)
    assert_equal 1, a.assay_organisms.count
    assert_include a.organisms, organism
    assert_include a.strains,strain
    assert_redirected_to assay_path(a)

  end

  test "should not create modelling assay with sample" do
    sample1=Factory(:sample)
    sample2=Factory(:sample)
    assert_no_difference("Assay.count") do
      post :create, :assay=>{:title=>"test",
                             :study_id=>studies(:metabolomics_study).id,
                             :assay_class_id=>assay_classes(:modelling_assay_class).id,
                             :sample_ids=>[sample1.id,sample2.id].join(",")
      }
    end
    assert_response :success
    assert assigns(:assay)
    assay = assigns(:assay)
    assert_equal 0, assay.samples.count
  end

  test "should delete assay with study" do
    a = assays(:assay_with_just_a_study)
    login_as(:model_owner)
    assert_difference('ActivityLog.count') do
      assert_difference('Assay.count', -1) do
        delete :destroy, :id => a
      end
    end

    assert_nil flash[:error]
    assert_redirected_to assays_path
  end

  test "should not delete assay when not project member" do
    a = assays(:assay_with_just_a_study)
    login_as(:aaron)
    assert_no_difference('ActivityLog.count') do
      assert_no_difference('Assay.count') do
        delete :destroy, :id => a
      end
    end

    assert flash[:error]
    assert_redirected_to a
  end

  test "should not delete assay when not project pal" do
    a = assays(:assay_with_just_a_study)
    login_as(:datafile_owner)
    assert_no_difference('ActivityLog.count') do
      assert_no_difference('Assay.count') do
        delete :destroy, :id => a
      end
    end

    assert flash[:error]
    assert_redirected_to a
  end

  test "should list correct organisms" do
    a = Factory :assay,:policy=>Factory(:public_policy)
    o1 = Factory(:organism,:title=>"Frog")

    Factory :assay_organism, :assay=>a,:organism=>o1

    get :show,:id=>a.id
    assert_response :success

    assert_select "p#organism" do
      assert_select "a[href=?]",organism_path(o1),:text=>"Frog"
    end

    o2 = Factory(:organism,:title=>"Slug")
    str = Factory :strain, :title=>"AAA111", :organism=>o2
    Factory :assay_organism,:assay=>a,:organism=>o2,:strain=>str
    get :show,:id=>a.id
        assert_response :success
        assert_select "p#organism" do
          assert_select "a[href=?]",organism_path(o1),:text=>"Frog"
          assert_select "a[href=?]",organism_path(o2),:text=>"Slug"
          assert_select "span.strain_info",:text=>str.info
        end
  end

  test "should show edit when not logged in" do
    logout
    a = Factory :experimental_assay,:contributor=>Factory(:person),:policy=>Factory(:editing_public_policy)
    get :edit,:id=>a
    assert_response :success

    a = Factory :modelling_assay,:contributor=>Factory(:person),:policy=>Factory(:editing_public_policy)
    get :edit,:id=>a
    assert_response :success
  end

  test "should not show delete button if not authorized to delete but can edit" do
    person = Factory :person
    a = Factory :assay,:contributor=>person,:policy=>Factory(:public_policy,:access_type=>Policy::EDITING)
    assert !a.can_manage?
    assert a.can_view?
    get :show,:id=>a.id
    assert_response :success
    assert_select "ul.sectionIcons" do
      assert_select "li" do
        assert_select "span",:text=>/Delete/,:count=>0
      end
    end
  end

  test "should show delete button in disable state if authorized to delete but has associated items" do
    person = Factory :person
    a = Factory :assay,:contributor=>person,:policy=>Factory(:public_policy)
    df = Factory :data_file, :contributor=>person,:policy=>Factory(:public_policy)
    Factory :assay_asset,:assay=>a,:asset=>df
    a.reload
    assert a.can_manage?
    assert_equal 1,a.assets.count
    assert !a.can_delete?
    get :show,:id=>a.id
    assert_response :success
    assert_select "ul.sectionIcons" do
      assert_select "li" do
        assert_select "span.disabled_icon",:text=>/Delete/,:count=>1
      end
    end
  end

  test "should show delete button in enabled state if authorized delete and has no associated items" do
    person = Factory :person
    a = Factory :assay,:contributor=>person,:policy=>Factory(:public_policy)

    assert a.can_manage?
    assert a.can_delete?
    get :show,:id=>a.id
    assert_response :success
    assert_select "ul.sectionIcons" do
      assert_select "li" do
        assert_select "span",:text=>/Delete/,:count=>1
        assert_select "span.disabled_icon",:text=>/Delete/,:count=>0
      end
    end
  end

  test "should not edit assay when not project pal" do
    a = assays(:assay_with_just_a_study)
    login_as(:datafile_owner)
    get :edit, :id => a
    assert flash[:error]
    assert_redirected_to a
  end

  test "admin should not edit somebody elses assay" do
    a = assays(:assay_with_just_a_study)
    login_as(:quentin)
    get :edit, :id => a
    assert flash[:error]
    assert_redirected_to a
  end

  test "should not delete assay with data files" do
    login_as(:model_owner)
    a = assays(:assay_with_no_study_but_has_some_files)
    assert_no_difference('ActivityLog.count') do
      assert_no_difference('Assay.count') do
        delete :destroy, :id => a
      end
    end
    assert flash[:error]
    assert_redirected_to a
  end

  test "should not delete assay with model" do
    login_as(:model_owner)
    a = assays(:assay_with_a_model)
    assert_no_difference('ActivityLog.count') do
      assert_no_difference('Assay.count') do
        delete :destroy, :id => a
      end
    end

    assert flash[:error]
    assert_redirected_to a
  end

  test "should not delete assay with publication" do
    login_as(:model_owner)
    a = assays(:assay_with_a_publication)
    assert_no_difference('ActivityLog.count') do
      assert_no_difference('Assay.count') do
        delete :destroy, :id => a
      end
    end

    assert flash[:error]
    assert_redirected_to a
  end

  test "should not delete assay with sops" do
    login_as(:model_owner)
    a = assays(:assay_with_no_study_but_has_some_sops)
    assert_no_difference('ActivityLog.count') do
      assert_no_difference('Assay.count') do
        delete :destroy, :id => a
      end
    end

    assert flash[:error]
    assert_redirected_to a
  end

  test "get new presents options for class" do
    login_as(:model_owner)
    get :new
    assert_response :success
    assert_select "a[href=?]", new_assay_path(:class=>:experimental), :count=>1
    assert_select "a", :text=>/An #{I18n.t('assays.experimental_assay')}/i, :count=>1
    assert_select "a[href=?]", new_assay_path(:class=>:modelling), :count=>1
    assert_select "a", :text=>/A #{I18n.t('assays.modelling_analysis')}/i, :count=>1
  end

  test "get new with class doesnt present options for class" do
    login_as(:model_owner)
    get :new, :class=>"experimental"
    assert_response :success
    assert_select "a[href=?]", new_assay_path(:class=>:experimental), :count=>0
    assert_select "a", :text=>/An #{I18n.t('assays.experimental_assay')}/i, :count=>0
    assert_select "a[href=?]", new_assay_path(:class=>:modelling), :count=>0
    assert_select "a", :text=>/A #{I18n.t('assays.modelling_analysis')}/i, :count=>0

    get :new, :class=>"modelling"
    assert_response :success
    assert_select "a[href=?]", new_assay_path(:class=>:experimental), :count=>0
    assert_select "a", :text=>/An #{I18n.t('assays.experimental_assay')}/i, :count=>0
    assert_select "a[href=?]", new_assay_path(:class=>:modelling), :count=>0
    assert_select "a", :text=>/A #{I18n.t('assays.modelling_analysis')}/i, :count=>0
  end

  test "data file list should only include those from project" do
    login_as(:model_owner)
    get :new, :class=>"experimental"
    assert_response :success
    assert_select "select#possible_data_files" do
      assert_select "option", :text=>/Sysmo Data File/, :count=>1
      assert_select "option", :text=>/Myexperiment Data File/, :count=>0
    end
  end

  test "download link for sop in tab" do
    login_as(:owner_of_my_first_sop)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_response :success

    assert_select "div.list_item div.list_item_actions" do
      sop = sops(:my_first_sop)
      path=download_sop_path(sop)
      assert_select "a[href=?]", path, :minumum=>1
    end
  end

  test "show link for sop in tab" do
    login_as(:owner_of_my_first_sop)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_response :success

    assert_select "div.list_item div.list_item_actions" do
      path=sop_path(sops(:my_first_sop))
      assert_select "a[href=?]", path, :minumum=>1
    end
  end

  test "edit link for sop in tabs" do
    login_as(:owner_of_my_first_sop)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_response :success

    assert_select "div.list_item div.list_item_actions" do
      path=edit_sop_path(sops(:my_first_sop))
      assert_select "a[href=?]", path, :minumum=>1
    end
  end

  test "download link for data_file in tabs" do
    login_as(:owner_of_my_first_sop)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_response :success

    assert_select "div.list_item div.list_item_actions" do
      df = data_files(:picture)
      path=download_data_file_path(df)
      assert_select "a[href=?]", path, :minumum=>1
    end
  end

  test "show link for data_file in tabs" do
    login_as(:owner_of_my_first_sop)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_response :success

    assert_select "div.list_item div.list_item_actions" do
      path=data_file_path(data_files(:picture))
      assert_select "a[href=?]", path, :minumum=>1
    end
  end

  test "edit link for data_file in tabs" do
    login_as(:owner_of_my_first_sop)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_response :success

    assert_select "div.list_item div.list_item_actions" do
      path=edit_data_file_path(data_files(:picture))
      assert_select "a[href=?]", path, :minumum=>1
    end
  end

  test "links have nofollow in sop tabs" do
    login_as(:owner_of_my_first_sop)
    sop_version=sops(:my_first_sop)
    sop_version.description="http://news.bbc.co.uk"
    sop_version.save!
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_select "div.list_item div.list_item_desc" do
      assert_select "a[rel=?]", "nofollow", :text=>/news\.bbc\.co\.uk/, :minimum=>1
    end
  end

  test "links have nofollow in data_files tabs" do
    login_as(:owner_of_my_first_sop)
    data_file_version=data_files(:picture)
    data_file_version.description="http://news.bbc.co.uk"
    data_file_version.save!
    assert_difference('ActivityLog.count') do
      get :show, :id=>assays(:metabolomics_assay)
    end

    assert_select "div.list_item div.list_item_desc" do
      assert_select "a[rel=?]", "nofollow", :text=>/news\.bbc\.co\.uk/, :minimum=>1
    end
  end

  def test_should_add_nofollow_to_links_in_show_page
    assert_difference('ActivityLog.count') do
      get :show, :id=> assays(:assay_with_links_in_description)
    end

    assert_select "div#description" do
      assert_select "a[rel=nofollow]"
    end
  end

    #checks that for an assay that has 2 sops and 2 datafiles, of which 1 is public and 1 private - only links to the public sops & datafiles are show
  def test_authorization_of_sops_and_datafiles_links
    #sanity check the fixtures are correct
    check_fixtures_for_authorization_of_sops_and_datafiles_links
    login_as(:model_owner)
    assay=assays(:assay_with_public_and_private_sops_and_datafiles)
    assert_difference('ActivityLog.count') do
      get :show, :id=>assay.id
    end

    assert_response :success

    assert_select "div.tabbertab" do
      assert_select "h3", :text=>"#{I18n.t('sop').pluralize} (1+1)", :count=>1
      assert_select "h3", :text=>"#{I18n.t('data_file').pluralize} (1+1)", :count=>1
    end

    assert_select "div.list_item" do
      assert_select "div.list_item_title a[href=?]", sop_path(sops(:sop_with_fully_public_policy)), :text=>"SOP with fully public policy", :count=>1
      assert_select "div.list_item_actions a[href=?]", sop_path(sops(:sop_with_fully_public_policy)), :count=>1
      assert_select "div.list_item_title a[href=?]", sop_path(sops(:sop_with_private_policy_and_custom_sharing)), :count=>0
      assert_select "div.list_item_actions a[href=?]", sop_path(sops(:sop_with_private_policy_and_custom_sharing)), :count=>0

      assert_select "div.list_item_title a[href=?]", data_file_path(data_files(:downloadable_data_file)), :text=>"Download Only", :count=>1
      assert_select "div.list_item_actions a[href=?]", data_file_path(data_files(:downloadable_data_file)), :count=>1
      assert_select "div.list_item_title a[href=?]", data_file_path(data_files(:private_data_file)), :count=>0
      assert_select "div.list_item_actions a[href=?]", data_file_path(data_files(:private_data_file)), :count=>0
    end

  end

  test "associated assets aren't lost on failed validation in create" do
    sop=sops(:sop_with_all_sysmo_users_policy)
    model=models(:model_with_links_in_description)
    datafile=data_files(:downloadable_data_file)
    rel=RelationshipType.first

    assert_no_difference('ActivityLog.count') do
      assert_no_difference("Assay.count", "Should not have added assay because the title is blank") do
        assert_no_difference("AssayAsset.count", "Should not have added assay assets because the assay validation failed") do
          #title is blank, so should fail validation
          post :create, :assay=>{
              :title=>"",
              :technology_type_uri=>"http://some-uri#tech",
              :assay_type_uri=>"http://some-uri#assay",
              :study_id=>studies(:metabolomics_study).id,
              :assay_class_id=>assay_classes(:modelling_assay_class).id
          },
               :assay_sop_ids=>["#{sop.id}"],
               :model_ids=>["#{model.id}"],
               :data_file_ids=>["#{datafile.id},#{rel.title}"]
        end
      end
    end

      #since the items are added to the UI by manipulating the DOM with javascript, we can't do assert_select on the HTML elements to check they are there.
      #so instead check for the relevant generated lines of javascript
    assert_select "script", :text=>/sop_title = '#{sop.title}'/, :count=>1
    assert_select "script", :text=>/sop_id = '#{sop.id}'/, :count=>1
    assert_select "script", :text=>/model_title = '#{model.title}'/, :count=>1
    assert_select "script", :text=>/model_id = '#{model.id}'/, :count=>1
    assert_select "script", :text=>/data_title = '#{datafile.title}'/, :count=>1
    assert_select "script", :text=>/data_file_id = '#{datafile.id}'/, :count=>1
    assert_select "script", :text=>/relationship_type = '#{rel.title}'/, :count=>1
    assert_select "script", :text=>/addDataFile/, :count=>1
    assert_select "script", :text=>/addSop/, :count=>1
    assert_select "script", :text=>/addModel/, :count=>1
  end

  test "should create with associated model sop data file and publication" do
    user = Factory :user
    login_as(user)
    sop=Factory :sop,:policy=>Factory(:public_policy),:contributor=>user
    model=Factory :model,:policy=>Factory(:public_policy),:contributor=>user
    df=Factory :data_file,:policy=>Factory(:public_policy),:contributor=>user
    pub=Factory :publication,:contributor=>user
    study=Factory :study, :policy=>Factory(:public_policy),:contributor=>user
    rel=RelationshipType.first

    assert_difference('ActivityLog.count') do
      assert_difference("Assay.count") do
        assert_difference("AssayAsset.count", 3) do
          assert_difference("Relationship.count") do

          post :create, :assay=>{
              :title=>"fish",
              :study_id=>study.id,
              :assay_class_id=>assay_classes(:modelling_assay_class).id
          },
               :assay_sop_ids=>["#{sop.id}"],
               :model_ids=>["#{model.id}"],
               :data_file_ids=>["#{df.id},#{rel.title}"],
               :related_publication_ids=>["#{pub.id}"]
          end
        end
      end
    end

    assert_not_nil assigns(:assay)
    assay = assigns(:assay)
    assay.reload #necessary to pickup the relationships for publications
    assert_equal [sop], assay.sop_masters
    assert_equal [df], assay.data_file_masters
    assert_equal [model],assay.model_masters
    assert_equal [pub], assay.related_publications

  end

  test "associated assets aren't lost on failed validation on update" do
    login_as(:model_owner)
    assay=assays(:assay_with_links_in_description)

      #remove any existing associated assets
    assay.assets.clear
    assay.save!
    assay.reload
    assert assay.sops.empty?
    assert assay.models.empty?
    assert assay.data_files.empty?

    sop=sops(:sop_with_all_sysmo_users_policy)
    model=models(:model_with_links_in_description)
    datafile=data_files(:downloadable_data_file)
    rel=RelationshipType.first

    assert_no_difference('ActivityLog.count') do
      assert_no_difference("Assay.count", "Should not have added assay because the title is blank") do
        assert_no_difference("AssayAsset.count", "Should not have added assay assets because the assay validation failed") do
          #title is blank, so should fail validation
          put :update, :id=>assay, :assay=>{:title=>"", :assay_class_id=>assay_classes(:modelling_assay_class).id},
              :assay_sop_ids=>["#{sop.id}"],
              :model_ids=>["#{model.id}"],
              :data_file_ids=>["#{datafile.id},#{rel.title}"]
        end
      end
    end

      #since the items are added to the UI by manipulating the DOM with javascript, we can't do assert_select on the HTML elements to check they are there.
      #so instead check for the relevant generated lines of javascript
    assert_select "script", :text=>/sop_title = '#{sop.title}'/, :count=>1
    assert_select "script", :text=>/sop_id = '#{sop.id}'/, :count=>1
    assert_select "script", :text=>/model_title = '#{model.title}'/, :count=>1
    assert_select "script", :text=>/model_id = '#{model.id}'/, :count=>1
    assert_select "script", :text=>/data_title = '#{datafile.title}'/, :count=>1
    assert_select "script", :text=>/data_file_id = '#{datafile.id}'/, :count=>1
    assert_select "script", :text=>/relationship_type = '#{rel.title}'/, :count=>1
    assert_select "script", :text=>/addDataFile/, :count=>1
    assert_select "script", :text=>/addSop/, :count=>1
    assert_select "script", :text=>/addModel/, :count=>1
  end

  def check_fixtures_for_authorization_of_sops_and_datafiles_links
    user=users(:model_owner)
    assay=assays(:assay_with_public_and_private_sops_and_datafiles)
    assert_equal 4, assay.assets.size
    assert_equal 2, assay.sops.size
    assert_equal 2, assay.data_files.size
    assert assay.sops.include?(sops(:sop_with_fully_public_policy).find_version(1))
    assert assay.sops.include?(sops(:sop_with_private_policy_and_custom_sharing).find_version(1))
    assert assay.data_files.include?(data_files(:downloadable_data_file).find_version(1))
    assert assay.data_files.include?(data_files(:private_data_file).find_version(1))

    assert sops(:sop_with_fully_public_policy).can_view? user
    assert !sops(:sop_with_private_policy_and_custom_sharing).can_view?(user)
    assert data_files(:downloadable_data_file).can_view?(user)
    assert !data_files(:private_data_file).can_view?(user)
  end

  test "filtering by study" do
    study=studies(:metabolomics_study)
    get :index, :filter => {:study => study.id}
    assert_response :success
  end

  test "filtering by investigation" do
    inv=investigations(:metabolomics_investigation)
    get :index, :filter => {:investigation => inv.id}
    assert_response :success
  end

  test "filtering by project" do
    project=projects(:sysmo_project)
    get :index, :filter => {:project => project.id}
    assert_response :success
  end

  test "filtering by person" do
    person = people(:person_for_model_owner)
    get :index, :filter=>{:person=>person.id}, :page=>"all"
    assert_response :success
    a = assays(:metabolomics_assay)
    a2 = assays(:modelling_assay_with_data_and_relationship)
    assert_select "div.list_items_container" do
      assert_select "a", :text=>a.title, :count=>1
      assert_select "a", :text=>a2.title, :count=>0
    end
  end

  test 'edit assay with selected projects scope policy' do
    proj = User.current_user.person.projects.first
    assay = Factory(:assay, :contributor => User.current_user.person,
                    :study => Factory(:study, :investigation => Factory(:investigation, :project_ids => [proj.id])),
                    :policy => Factory(:policy,
                                       :sharing_scope => Policy::ALL_SYSMO_USERS,
                                       :access_type => Policy::NO_ACCESS,
                                       :permissions => [Factory(:permission, :contributor => proj, :access_type => Policy::EDITING)]))
    get :edit, :id => assay.id
  end

  test "should create sharing permissions 'with your project and with all SysMO members'" do
    login_as(:quentin)
    a = {:title=>"test",
         :study_id=>studies(:metabolomics_study).id,
         :assay_class_id=>assay_classes(:experimental_assay_class).id,
         :sample_ids=>[Factory(:sample).id]}
    assert_difference('ActivityLog.count') do
      assert_difference('Assay.count') do
        post :create, :assay => a, :sharing=>{"access_type_#{Policy::ALL_SYSMO_USERS}"=>Policy::VISIBLE, :sharing_scope=>Policy::ALL_SYSMO_USERS, :your_proj_access_type => Policy::ACCESSIBLE}
      end
    end

    assay=assigns(:assay)
    assert_redirected_to assay_path(assay)
    assert_equal Policy::ALL_SYSMO_USERS, assay.policy.sharing_scope
    assert_equal Policy::VISIBLE, assay.policy.access_type
    assert_equal assay.policy.permissions.count, 1

    assay.policy.permissions.each do |permission|
      assert_equal permission.contributor_type, 'Project'
      assert assay.study.investigation.project_ids.include?(permission.contributor_id)
      assert_equal permission.policy_id, assay.policy_id
      assert_equal permission.access_type, Policy::ACCESSIBLE
    end
  end

  test "should update sharing permissions 'with your project and with all SysMO members'" do
    login_as Factory(:user)
    assay= Factory(:assay,
                   :policy => Factory(:private_policy),
                   :contributor => User.current_user.person,
                   :study => (Factory(:study, :investigation => (Factory(:investigation,
                                                                         :project_ids => [Factory(:project).id, Factory(:project).id])))))

    assert assay.can_manage?
    assert_equal Policy::PRIVATE, assay.policy.sharing_scope
    assert_equal Policy::NO_ACCESS, assay.policy.access_type
    assert assay.policy.permissions.empty?

    assert_difference('ActivityLog.count') do
      put :update, :id => assay, :assay => {}, :sharing => {"access_type_#{Policy::ALL_SYSMO_USERS}"=>Policy::ACCESSIBLE, :sharing_scope => Policy::ALL_SYSMO_USERS, :your_proj_access_type => Policy::EDITING}
    end

    assay.reload
    assert_redirected_to assay_path(assay)
    assert_equal Policy::ALL_SYSMO_USERS, assay.policy.sharing_scope
    assert_equal Policy::ACCESSIBLE, assay.policy.access_type
    assert_equal 2, assay.policy.permissions.length

    assay.policy.permissions.each do |update_permission|
      assert_equal update_permission.contributor_type, 'Project'
      assert assay.projects.map(&:id).include?(update_permission.contributor_id)
      assert_equal update_permission.policy_id, assay.policy_id
      assert_equal update_permission.access_type, Policy::EDITING
    end
  end

  test 'should have associated datafiles, models, on modelling assay show page' do
    df = Factory(:data_file,:contributor => User.current_user)
    model = Factory(:model,:contributor => User.current_user)
    assay= Factory(:assay,:contributor => User.current_user.person,
                            :study => (Factory(:study, :investigation => (Factory(:investigation)))))
    assay.data_file_masters << df
    assay.model_masters << model
    assert assay.save
    assert assay.is_modelling?

    get :show, :id => assay
    assert_response :success
    assert_select "a[href=?]", data_file_path(df), :text => df.title
    assert_select "a[href=?]", model_path(model), :text => model.title
  end

  test 'should have associated datafiles, models and sops on assay index page for modelling assays' do
      Assay.delete_all
      df = Factory(:data_file,:contributor => User.current_user)
      model = Factory(:model,:contributor => User.current_user)
      sop = Factory(:sop,:contributor => User.current_user)
      assay= Factory(:modelling_assay,:contributor => User.current_user.person,
                              :study => (Factory(:study, :investigation => (Factory(:investigation)))))
      assay.data_file_masters << df
      assay.model_masters << model
      assay.sop_masters << sop
      assert assay.save
      assert assay.is_modelling?

      get :index
      assert_response :success
      assert_select "a[href=?]", data_file_path(df), :text => df.title
      assert_select "a[href=?]", model_path(model), :text => model.title
      assert_select "a[href=?]", sop_path(sop), :text => sop.title
  end

  test 'should have only associated datafiles and sops on assay index page for experimental assays' do
        Assay.delete_all
        df = Factory(:data_file,:contributor => User.current_user)
        model = Factory(:model,:contributor => User.current_user)
        sop = Factory(:sop,:contributor => User.current_user)
        assay= Factory(:experimental_assay,:contributor => User.current_user.person,
                                :study => (Factory(:study, :investigation => (Factory(:investigation)))))
        assay.data_file_masters << df
        assay.model_masters << model
        assay.sop_masters << sop
        assert assay.save
        assert assay.is_experimental?

        get :index
        assert_response :success
        assert_select "a[href=?]", data_file_path(df), :text => df.title
        assert_select "a[href=?]", model_path(model), :text => model.title, :count => 0
        assert_select "a[href=?]", sop_path(sop), :text => sop.title
  end

  test "should not show private data or model title on modelling analysis summary" do
    df = Factory(:data_file, :title=>"private data file", :policy=>Factory(:private_policy))
    df2 = Factory(:data_file, :title=>"public data file", :policy=>Factory(:public_policy))
    model = Factory(:model, :title=>"private model", :policy=>Factory(:private_policy))
    model2 = Factory(:model, :title=>"public model", :policy=>Factory(:public_policy))
    assay = Factory(:modelling_assay,:policy=>Factory(:public_policy))

    assay.data_file_masters << df
    assay.data_file_masters << df2
    assay.model_masters << model
    assay.model_masters << model2

    assay.save!

    login_as Factory(:person)

    get :show,:id=>assay.id
    assert_response :success
    assert_select "div.data_model_relationship" do
      assert_select "ul.related_models" do
        assert_select "li a[href=?]",model_path(model2),:text=>/#{model2.title}/,:count=>1
        assert_select "li a[href=?]",model_path(model),:text=>/#{model.title}/,:count=>0
        assert_select "li",:text=>/Hidden/,:count=>1
      end
      assert_select "ul.related_data_files" do
        assert_select "li a[href=?]",data_file_path(df2),:text=>/#{df2.title}/,:count=>1
        assert_select "li a[href=?]",data_file_path(df),:text=>/#{df.title}/,:count=>0
        assert_select "li",:text=>/Hidden/,:count=>1
      end
    end

  end

  test "preview assay with associated hidden items" do
    assay = Factory(:assay,:policy=>Factory(:public_policy))
    private_df = Factory(:data_file,:policy=>Factory(:private_policy))
    assay.data_file_masters << private_df
    assay.save!
    login_as Factory(:person)
    xhr(:get, :preview,{:id=>assay.id})
    assert_response :success
  end

  test "should not show investigation and study title if they are hidden on assay show page" do
    investigation = Factory(:investigation,
                            :policy=>Factory(:private_policy),
                            :contributor => User.current_user)
    study = Factory(:study,
                    :policy=>Factory(:private_policy),
                    :contributor => User.current_user,
                    :investigation => investigation)
    assay = Factory(:assay,
                    :policy=>Factory(:public_policy),
                    :study => study)

    logout
    get :show, :id => assay
    assert_response :success
    assert_select "p#investigation" do
      assert_select "span.none_text", :text => /hidden item/, :count => 1
    end
    assert_select "p#study" do
      assert_select "span.none_text", :text => /hidden item/, :count => 1
    end
  end

  test "edit should include tags element" do
    assay = Factory(:assay,:policy=>Factory(:public_policy))
    get :edit, :id=>assay.id
    assert_response :success

    assert_select "div.foldTitle",:text=>/Tags/,:count=>1
    assert_select "div#tag_ids",:count=>1
  end

  test "new should include tags element" do
    get :new,:class=>:experimental
    assert_response :success
    assert_select "div.foldTitle",:text=>/Tags/,:count=>1
    assert_select "div#tag_ids",:count=>1
  end

  test "edit should include not include tags element when tags disabled" do
    with_config_value :tagging_enabled,false do
      assay = Factory(:assay,:policy=>Factory(:public_policy))
      get :edit, :id=>assay.id
      assert_response :success

      assert_select "div.foldTitle",:text=>/Tags/,:count=>0
      assert_select "div#tag_ids",:count=>0
    end
  end

  test "new should not include tags element when tags disabled" do
    with_config_value :tagging_enabled,false do
      get :new,:class=>:experimental
      assert_response :success
      assert_select "div.foldTitle",:text=>/Tags/,:count=>0
      assert_select "div#tag_ids",:count=>0
    end
  end

  test "new object based on existing one" do
    study = Factory(:study,:policy=>Factory(:public_policy))
    assay = Factory(:assay,:policy=>Factory(:public_policy),:title=>"the assay",:study=>study)
    assert assay.can_view?
    assert assay.study.can_edit?
    get :new_object_based_on_existing_one,:id=>assay.id
    assert_response :success
    assert_select "textarea#assay_title",:text=>"the assay"
    assert_select "select#assay_study_id option[selected][value=?]",assay.study.id,:count=>1
  end

  test "new object based on existing one when unauthorised to view" do
    assay = Factory(:assay,:policy=>Factory(:private_policy),:title=>"the assay")
    refute assay.can_view?
    get :new_object_based_on_existing_one,:id=>assay.id
    assert_redirected_to assays_path
    refute_nil flash[:error]
  end

  test "new object based on existing one when can view but not logged in" do
    assay = Factory(:assay,:policy=>Factory(:public_policy))
    logout
    assert assay.can_view?
    get :new_object_based_on_existing_one, :id=>assay.id
    assert_redirected_to assay
    refute_nil flash[:error]
  end

  test "should show experimental assay types for new experimental assay" do
    get :new,:class=>:experimental
    assert_response :success
    assert_select "label",:text=>/assay type/i
    assert_select "select#assay_assay_type_uri" do
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Fluxomics",:text=>/Fluxomics/i
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Cell_cycle",:text=>/Cell cycle/i,:count=>0
    end
  end

  test "should show modelling assay types for new modelling assay" do
    get :new,:class=>:modelling
    assert_response :success
    assert_select "label",:text=>/Biological problem addressed/i
    assert_select "select#assay_assay_type_uri" do
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Cell_cycle",:text=>/Cell cycle/i
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Fluxomics",:text=>/Fluxomics/i,:count=>0
    end
  end

  test "should show experimental assay types when editing experimental assay" do
    a = Factory(:experimental_assay,:contributor=>User.current_user.person)
    get :edit,:id=>a.id
    assert_response :success
    assert_select "label",:text=>/assay type/i
    assert_select "select#assay_assay_type_uri" do
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Fluxomics",:text=>/Fluxomics/i
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Cell_cycle",:text=>/Cell cycle/i,:count=>0
    end
  end

  test "should show modelling assay types when editing modelling assay" do
    a = Factory(:modelling_assay,:contributor=>User.current_user.person)
    get :edit,:id=>a.id
    assert_response :success
    assert_select "label",:text=>/Biological problem addressed/i
    assert_select "select#assay_assay_type_uri" do
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Cell_cycle",:text=>/Cell cycle/i
      assert_select "option[value=?]","http://www.mygrid.org.uk/ontology/JERMOntology#Fluxomics",:text=>/Fluxomics/i,:count=>0
    end
  end

  test "assays filtered by investigation via nested routing" do
    assert_routing "investigations/1/assays",{controller:"assays",action:"index",investigation_id:"1"}
    assay = Factory(:assay,:policy=>Factory(:public_policy))
    inv = assay.study.investigation
    assay2 = Factory(:assay,:policy=>Factory(:public_policy))
    refute_nil(inv)
    refute_equal assay.study.investigation, assay2.study.investigation
    get :index,investigation_id:inv.id
    assert_response :success
    assert_select "div.list_item_title" do
      assert_select "p > a[href=?]",assay_path(assay),:text=>assay.title
      assert_select "p > a[href=?]",assay_path(assay2),:text=>assay2.title,:count=>0
    end
  end

  test "assays filtered by study via nested routing" do
    assert_routing "studies/1/assays",{controller:"assays",action:"index",study_id:"1"}
    assay = Factory(:assay,:policy=>Factory(:public_policy))
    study = assay.study
    assay2 = Factory(:assay,:policy=>Factory(:public_policy))

    refute_equal assay.study, assay2.study
    get :index,study_id:study.id
    assert_response :success
    assert_select "div.list_item_title" do
      assert_select "p > a[href=?]",assay_path(assay),:text=>assay.title
      assert_select "p > a[href=?]",assay_path(assay2),:text=>assay2.title,:count=>0
    end
  end

  test "logged out user can't see new" do
    logout
    get :new
    assert_redirected_to assays_path
  end

  test "assays filtered by strain through nested route" do
    assert_routing "strains/3/assays",{controller:"assays",action:"index",strain_id:"3"}
    ao1 = Factory(:assay_organism,:assay=>Factory(:assay,:policy=>Factory(:public_policy)))
    ao2 = Factory(:assay_organism,:assay=>Factory(:assay,:policy=>Factory(:public_policy)))
    strain1 = ao1.strain
    strain2 = ao2.strain
    assay1=ao1.assay
    assay2=ao2.assay

    refute_nil strain1
    refute_nil strain2
    refute_equal strain1,strain2
    refute_nil assay1
    refute_nil assay2
    refute_equal assay1,assay2

    assert_include assay1.strains,strain1
    assert_include assay2.strains,strain2

    assert_include strain1.assays,assay1
    assert_include strain2.assays,assay2

    assert strain1.can_view?
    assert strain2.can_view?

    get :index,strain_id:strain1.id
    assert_response :success

    assert_select "div.list_item_title" do
      assert_select "a[href=?]",assay_path(assay1),:text=>assay1.title
      assert_select "a[href=?]",assay_path(assay2),:text=>assay2.title,:count=>0
    end

  end

end